Skip to content

Commit 97fb06a

Browse files
committed
Problem02 using ListNode
1 parent 0dcbad3 commit 97fb06a

File tree

1 file changed

+6
-4
lines changed
  • java8/src/main/java/com/shekhargulati/leetcode/algorithms

1 file changed

+6
-4
lines changed

java8/src/main/java/com/shekhargulati/leetcode/algorithms/Problem02.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@ public static void main(String[] args) {
3232
int b = second.val;
3333
first = first.next;
3434
second = second.next;
35-
int sum = a + b;
36-
if (a + b >= 10) {
37-
result.add(rem + sum % 10);
35+
int sum = a + b + rem;
36+
if (sum >= 10) {
37+
sum = sum % 10;
3838
rem = 1;
3939
} else {
40-
result.add(rem + sum);
4140
rem = 0;
4241
}
42+
result.add(sum);
4343
}
44+
45+
System.out.println(result);
4446
long end = System.currentTimeMillis();
4547
System.out.println(String.format("Total time taken %d millis", (end - start)));
4648

0 commit comments

Comments
 (0)