class Solution {
private static boolean f=false;
public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {
Stack<Integer> stack=new Stack<>();
while(l1!=null && l2!=null) {
int v= l1.val+l2.val;
stack.push((f?(v+1):v)%10);
if(v>9)
f=true;
else
f=false;
l1=l1.next;
l2=l2.next;
}
if(f)
stack.push(1);
ListNode node =new ListNode(0);
while(!stack.isEmpty()) {
ListNode temp = new ListNode(stack.pop());
temp.next=node.next;
node.next=temp;
}
node=node.next;
return node;
}
}"Run Code" situation:
input [9] [9]
output [8] [1]
"Submit Solution” situation:
output [9][1]
why???