leetcode 2. Add 2 numbers
knowledge point:
1. listNode check null
listNode dummy node
traverse using node=node.next
2. Add number:
res =sum%10
carry=sum/10
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
if(l1==null) return l2;
if(l2==null) return l1;
ListNode dummy=new ListNode(0);
ListNode res=dummy;
int sum=0;
while(l1!=null || l2!=null){
if(l1!=null){
sum+=l1.val;
l1=l1.next;
}
if(l2!=null){
sum+=l2.val;
l2=l2.next;
}
res.next=new ListNode(sum%10);
res=res.next;
sum=sum/10;
}
if(sum>0) res.next=new ListNode(sum);
return dummy.next;
}