class Solution { public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode head = new ListNode(0); ListNode ln = head; ListNode ln1 = l1; ListNode ln2 = l2; int temp = 0; while (ln1 != null || ln2 != null) { if (ln1 == null) { ln.next = new ListNode((ln2.val + temp) % 10); temp = (ln2.val + temp) / 10; ln = ln.next; ln2 = ln2.next; } else if(ln2 == null) { ln.next = new ListNode((ln1.val + temp) % 10); temp = (ln1.val + temp) / 10; ln = ln.next; ln1 = ln1.next; } else { ln.next = new ListNode((ln1.val+ln2.val + temp) % 10); temp = (ln1.val + ln2.val+ temp) / 10; ln = ln.next; ln1 = ln1.next; ln2 = ln2.next; } }if(temp!=0) ln.next = new ListNode(1); return head.next; } }2. 两数相加