File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/main/java/com/ctci/linkedlists Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 8
8
*/
9
9
public class SumLists {
10
10
11
+ /**
12
+ * You have two numbers represented by a linked list, where each node contains a single digit. The digits are
13
+ * stored in reverse order, such that the 1's digit is at the head of the list (or in other words, the least
14
+ * significant digit is stored at the head of the list). Write a function that adds the two numbers and returns
15
+ * the sum as a linked list.
16
+ * <p>
17
+ * EXAMPLE
18
+ * Input: (7-> 1 -> 6) + (5 -> 9 -> 2).That is, 617 + 295.
19
+ * Output: 2 -> 1 -> 9. That is, 912.
20
+ *
21
+ * @param num1
22
+ * @param num2
23
+ * @return
24
+ */
11
25
private static Node sumLists (Node num1 , Node num2 ) {
12
26
int carry = 0 ;
13
27
int sum ;
You can’t perform that action at this time.
0 commit comments