AddTwoNumbers { public ListNode addTwoNumbersI(ListNode<Integer> l1, ListNode<Integer> l2) { if (l1 == null) return l2; if (l2 == null) return l1; ListNode sum = null; ListNode prev = null; int adder = 0; while(l1 != null && l2 != null) { int v = l1.val + l2.val + adder; ListNode<Integer> current = new ListNode(v >= 10 ? v - 10 : v); if (sum == null) { sum = current; } else { prev.next = current; } adder = v >= 10 ? 1 : 0; prev = current; l1 = l1.next; l2 = l2.next; } if (l2 != null) { l1 = l2; } while (l1 != null) { int v = l1.val + adder; ListNode<Integer> current = new ListNode(v >= 10 ? v - 10 : v); prev.next = current; adder = v >= 10 ? 1 : 0; prev = current; l1 = l1.next; } if (adder != 0) { ListNode current = new ListNode(adder); prev.next = current; } return sum; }  ListNode addTwoNumbersI(ListNode<Integer> l1, ListNode<Integer> l2); ListNode addTwoNumbersII(ListNode<Integer> l1, ListNode<Integer> l2);  }
@Test(dataProvider = "addersI") public void testAddNumbersI(ListNode<Integer> adder1, ListNode<Integer> adder2, List<Integer> expectedSum) { ListNode<Integer> actual = new AddTwoNumbers().addTwoNumbersI(adder1, adder2); TestUtilities.assertLinkedListValues(actual, expectedSum); }