I am trying to convert a string to a linked list where each digit is in a separate node.
I set on it trying to debug it but I can't seem to find what's wrong with my logic. I keep getting a weird 2-digit number in each node and not necessarily even the digits that appear in the string.
Please note the ListNode is the class I create a new node object with.
String number = "807";
int size = number.length();
int pos = 0;
ListNode dummyhead = new ListNode();
ListNode curr = dummyhead;
while (size > 0){
curr.next = new ListNode(number.charAt(pos));
pos++;
size--;
curr = curr.next;
}
return dummyhead.next;