/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
ListNode ret = null;
ListNode curr = null;
int i = 0;
while(l1!=null || l2!=null || i>0){
l1 = l1==null?new ListNode(0):l1;
l2 = l2==null?new ListNode(0):l2;
int sum = l1.val+l2.val+i;
ListNode temp = new ListNode(sum%10);
i=sum/10;
if(ret==null) {
ret = temp;
curr = ret;
}else {
curr.next = temp;
curr = curr.next;
}
l1 = l1.next;
l2 = l2.next;
}
return ret;
}
}
暂无
暂无
暂无