I am writing a program to slice a number into its digits and to store the digits in a linked list in reverse order. But I am not able to understand how to return the linked list?
I have tried creating a head ListNode but failed in it.
public class ListNode {
int val;
ListNode next;
ListNode(int x) { val = x; }
}
class Solution{
int sum=123;
public ListNode sol(){
answer = new ListNode(0);
while (sum > 0) {
int digit = sum % 10;
answer= new ListNode(digit);
answer= answer.next;
sum /= 10;
}
return //////
}
}