Skip to content

Commit 3319808

Browse files
refactor 2
1 parent 7b605bd commit 3319808

File tree

2 files changed

+0
-36
lines changed

2 files changed

+0
-36
lines changed

src/main/java/com/fishercoder/solutions/_2.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,35 +40,4 @@ public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
4040
}
4141
}
4242

43-
public static class Solution2 {
44-
public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
45-
ListNode pre = new ListNode(-1);
46-
ListNode head = new ListNode(0);
47-
pre.next = head;
48-
int carry = 0;
49-
while (l1 != null || l2 != null) {
50-
int val = carry;
51-
if (l1 != null) {
52-
val += l1.val;
53-
l1 = l1.next;
54-
}
55-
if (l2 != null) {
56-
val += l2.val;
57-
l2 = l2.next;
58-
}
59-
if (val >= 10) {
60-
val %= 10;
61-
carry = 1;
62-
} else {
63-
carry = 0;
64-
}
65-
head.next = new ListNode(val);
66-
head = head.next;
67-
}
68-
if (carry != 0) {
69-
head.next = new ListNode(carry);
70-
}
71-
return pre.next.next;
72-
}
73-
}
7443
}

src/test/java/com/fishercoder/_2Test.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@
1010

1111
public class _2Test {
1212
private static _2.Solution1 solution1;
13-
private static _2.Solution2 solution2;
1413
private static ListNode l1;
1514
private static ListNode l2;
1615
private static ListNode expected;
1716

1817
@BeforeClass
1918
public static void setup() {
2019
solution1 = new _2.Solution1();
21-
solution2 = new _2.Solution2();
2220
}
2321

2422
@Test
2523
public void test1() {
2624
l1 = LinkedListUtils.contructLinkedList(new int[]{2, 4, 3});
2725
l2 = LinkedListUtils.contructLinkedList(new int[]{5, 6, 4});
2826
expected = LinkedListUtils.contructLinkedList(new int[]{7, 0, 8});
29-
assertEquals(expected, solution2.addTwoNumbers(l1, l2));
3027
assertEquals(expected, solution1.addTwoNumbers(l1, l2));
3128
}
3229

@@ -36,7 +33,6 @@ public void test2() {
3633
l2 = LinkedListUtils.contructLinkedList(new int[]{0});
3734
expected = LinkedListUtils.contructLinkedList(new int[]{1, 8});
3835
assertEquals(expected, solution1.addTwoNumbers(l1, l2));
39-
assertEquals(expected, solution2.addTwoNumbers(l1, l2));
4036
}
4137

4238
@Test
@@ -45,6 +41,5 @@ public void test3() {
4541
l2 = LinkedListUtils.contructLinkedList(new int[]{5});
4642
expected = LinkedListUtils.contructLinkedList(new int[]{0, 1});
4743
assertEquals(expected, solution1.addTwoNumbers(l1, l2));
48-
assertEquals(expected, solution2.addTwoNumbers(l1, l2));
4944
}
5045
}

0 commit comments

Comments
 (0)