MCPcopy Index your code
hub / github.com/careercup/ctci / addListsHelper

Method addListsHelper

java/Chapter 2/Question2_5/QuestionB.java:13–24  ·  view source on GitHub ↗
(LinkedListNode l1, LinkedListNode l2)

Source from the content-addressed store, hash-verified

11 }
12
13 private static PartialSum addListsHelper(LinkedListNode l1, LinkedListNode l2) {
14 if (l1 == null && l2 == null) {
15 PartialSum sum = new PartialSum();
16 return sum;
17 }
18 PartialSum sum = addListsHelper(l1.next, l2.next);
19 int val = sum.carry + l1.data + l2.data;
20 LinkedListNode full_result = insertBefore(sum.sum, val % 10);
21 sum.sum = full_result;
22 sum.carry = val / 10;
23 return sum;
24 }
25
26 private static LinkedListNode addLists(LinkedListNode l1, LinkedListNode l2) {
27 int len1 = length(l1);

Callers 1

addListsMethod · 0.95

Calls 1

insertBeforeMethod · 0.95

Tested by

no test coverage detected