Skip to content

Commit a69f5cd

Browse files
authored
Improved tasks 19-25
1 parent ca88df1 commit a69f5cd

File tree

5 files changed

+15
-77
lines changed

5 files changed

+15
-77
lines changed
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
import unittest
2-
import importlib
3-
4-
mod = importlib.import_module('Solution0019')
5-
6-
class ListNode:
7-
def __init__(self, val=0, next=None):
8-
self.val = val
9-
self.next = next
10-
11-
def __str__(self):
12-
return ""
2+
from Solution0019 import Solution, ListNode
133

144
def construct_linked_list(values):
155
dummy = ListNode(0)
@@ -19,7 +9,6 @@ def construct_linked_list(values):
199
curr = curr.next
2010
return dummy.next
2111

22-
2312
def to_string(head):
2413
parts = []
2514
curr = head
@@ -30,13 +19,11 @@ def to_string(head):
3019

3120
class SolutionTest(unittest.TestCase):
3221
def test_removeNthFromEnd(self):
33-
mod.ListNode = ListNode
3422
node1 = construct_linked_list([1, 2, 3, 4, 5])
35-
result = mod.Solution().removeNthFromEnd(node1, 2)
23+
result = Solution().removeNthFromEnd(node1, 2)
3624
self.assertEqual(to_string(result), "1, 2, 3, 5")
3725

3826
def test_removeNthFromEnd2(self):
39-
mod.ListNode = ListNode
4027
node1 = ListNode(1)
41-
result = mod.Solution().removeNthFromEnd(node1, 1)
28+
result = Solution().removeNthFromEnd(node1, 1)
4229
self.assertIsNone(result)
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import unittest
2-
import importlib
3-
4-
mod = importlib.import_module('Solution0021')
5-
6-
class ListNode:
7-
def __init__(self, val=0, next=None):
8-
self.val = val
9-
self.next = next
10-
2+
from Solution0021 import Solution, ListNode
113

124
def from_list(values):
135
dummy = ListNode(0)
@@ -17,7 +9,6 @@ def from_list(values):
179
curr = curr.next
1810
return dummy.next
1911

20-
2112
def to_string(head):
2213
parts = []
2314
curr = head
@@ -26,15 +17,11 @@ def to_string(head):
2617
curr = curr.next
2718
return ", ".join(parts)
2819

29-
3020
class SolutionTest(unittest.TestCase):
3121
def test_mergeTwoLists(self):
32-
mod.ListNode = ListNode
3322
l1 = from_list([1, 2, 4])
3423
l2 = from_list([1, 3, 4])
35-
self.assertEqual(to_string(mod.Solution().mergeTwoLists(l1, l2)), "1, 1, 2, 3, 4, 4")
36-
24+
self.assertEqual(to_string(Solution().mergeTwoLists(l1, l2)), "1, 1, 2, 3, 4, 4")
3725

3826
def test_mergeTwoLists2(self):
39-
mod.ListNode = ListNode
40-
self.assertEqual(to_string(mod.Solution().mergeTwoLists(ListNode(0), ListNode(0))), "0, 0")
27+
self.assertEqual(to_string(Solution().mergeTwoLists(ListNode(0), ListNode(0))), "0, 0")
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import unittest
2-
import importlib
3-
4-
mod = importlib.import_module('Solution0023')
5-
6-
class ListNode:
7-
def __init__(self, val=0, next=None):
8-
self.val = val
9-
self.next = next
10-
2+
from Solution0023 import Solution, ListNode
113

124
def from_list(values):
135
dummy = ListNode(0)
@@ -17,7 +9,6 @@ def from_list(values):
179
curr = curr.next
1810
return dummy.next
1911

20-
2112
def to_string(head):
2213
parts = []
2314
curr = head
@@ -26,20 +17,17 @@ def to_string(head):
2617
curr = curr.next
2718
return ", ".join(parts)
2819

29-
3020
class SolutionTest(unittest.TestCase):
3121
def test_mergeKLists(self):
32-
mod.ListNode = ListNode
3322
head1 = from_list([1, 4, 5])
3423
head2 = from_list([1, 3, 4])
3524
head3 = from_list([2, 6])
36-
result = mod.Solution().mergeKLists([head1, head2, head3])
25+
result = Solution().mergeKLists([head1, head2, head3])
3726
self.assertEqual(to_string(result), "1, 1, 2, 3, 4, 4, 5, 6")
3827

3928
def test_mergeKLists2(self):
40-
mod.ListNode = ListNode
4129
head1 = from_list([1, 3, 5, 7, 11])
4230
head2 = from_list([2, 8, 12])
4331
head3 = from_list([4, 6, 9, 10])
44-
result = mod.Solution().mergeKLists([head1, head2, head3])
32+
result = Solution().mergeKLists([head1, head2, head3])
4533
self.assertEqual(to_string(result), "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12")
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import unittest
2-
import importlib
3-
4-
mod = importlib.import_module('Solution0024')
5-
6-
class ListNode:
7-
def __init__(self, val=0, next=None):
8-
self.val = val
9-
self.next = next
10-
2+
from Solution0024 import Solution, ListNode
113

124
def from_list(values):
135
dummy = ListNode(0)
@@ -17,7 +9,6 @@ def from_list(values):
179
curr = curr.next
1810
return dummy.next
1911

20-
2112
def to_string(head):
2213
parts = []
2314
curr = head
@@ -26,15 +17,12 @@ def to_string(head):
2617
curr = curr.next
2718
return ", ".join(parts)
2819

29-
3020
class SolutionTest(unittest.TestCase):
3121
def test_swapPairs(self):
32-
mod.ListNode = ListNode
3322
head = from_list([1, 2, 3, 4])
34-
result = mod.Solution().swapPairs(head)
23+
result = Solution().swapPairs(head)
3524
self.assertEqual(to_string(result), "2, 1, 4, 3")
3625

3726
def test_swapPairs2(self):
38-
mod.ListNode = ListNode
39-
result = mod.Solution().swapPairs(ListNode(1))
27+
result = Solution().swapPairs(ListNode(1))
4028
self.assertEqual(to_string(result), "1")
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import unittest
2-
import importlib
3-
4-
mod = importlib.import_module('Solution0025')
5-
6-
class ListNode:
7-
def __init__(self, val=0, next=None):
8-
self.val = val
9-
self.next = next
10-
2+
from Solution0025 import Solution, ListNode
113

124
def from_list(values):
135
dummy = ListNode(0)
@@ -17,7 +9,6 @@ def from_list(values):
179
curr = curr.next
1810
return dummy.next
1911

20-
2112
def to_string(head):
2213
parts = []
2314
curr = head
@@ -26,16 +17,13 @@ def to_string(head):
2617
curr = curr.next
2718
return ", ".join(parts)
2819

29-
3020
class SolutionTest(unittest.TestCase):
3121
def test_reverseKGroup(self):
32-
mod.ListNode = ListNode
3322
head = from_list([1, 2, 3, 4, 5])
34-
result = mod.Solution().reverseKGroup(head, 2)
23+
result = Solution().reverseKGroup(head, 2)
3524
self.assertEqual(to_string(result), "2, 1, 4, 3, 5")
3625

3726
def test_reverseKGroup2(self):
38-
mod.ListNode = ListNode
3927
head = from_list([1, 2, 3, 4, 5])
40-
result = mod.Solution().reverseKGroup(head, 3)
28+
result = Solution().reverseKGroup(head, 3)
4129
self.assertEqual(to_string(result), "3, 2, 1, 4, 5")

0 commit comments

Comments
 (0)