public ListNode addTwoNumbers(ListNode l1, ListNode l2) { ListNode dummy = new ListNode(0); ListNode p1 = l1; ListNode p2 = l2; ListNode cur = dummy; int sum = 0; while (p1 != null || p2 != null) { if (p1 != null) { sum += p1.val; p1 = p1.next; } if (p2 != null) { sum += p2.val; p2 = p2.next; } cur.next = new ListNode(sum % 10); cur = cur.next; sum = sum / 10; } if(sum > 0){ cur.next = new ListNode(1); } return dummy.next; }