We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b228fa7 commit befa3afCopy full SHA for befa3af
src/main/java/com/ctci/linkedlists/SumLists.java
@@ -8,6 +8,20 @@
8
*/
9
public class SumLists {
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
+ */
25
private static Node sumLists(Node num1, Node num2) {
26
int carry = 0;
27
int sum;
0 commit comments