Skip to content

Commit 83baacf

Browse files
authored
Added tests 198-234
1 parent 4d6b1f4 commit 83baacf

File tree

19 files changed

+258
-0
lines changed

19 files changed

+258
-0
lines changed

src/main/python/g0101_0200/s0198_house_robber/Solution0198.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# #Level_2_Day_12_Dynamic_Programming #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP
44
# #Big_O_Time_O(n)_Space_O(n) #2025_07_25_Time_0_ms_(100.00%)_Space_17.77_MB_(54.18%)
55

6+
from typing import List
7+
68
class Solution:
79
def rob(self, nums: List[int]) -> int:
810
if len(nums) == 0:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0198 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_rob(self):
6+
self.assertEqual(Solution().rob([1,2,3,1]), 4)
7+
8+
def test_rob2(self):
9+
self.assertEqual(Solution().rob([2,7,9,3,1]), 12)
10+
11+
def test_rob3(self):
12+
self.assertEqual(Solution().rob([]), 0)

src/main/python/g0101_0200/s0200_number_of_islands/Solution0200.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# #Top_Interview_150_Graph_General #Big_O_Time_O(M*N)_Space_O(M*N)
66
# #2025_07_25_Time_234_ms_(82.73%)_Space_19.96_MB_(95.69%)
77

8+
from typing import List
9+
810
class Solution:
911
def numIslands(self, grid: List[List[str]]) -> int:
1012
def dfs(grid, x, y):
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import unittest
2+
from Solution0200 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_numIslands(self):
6+
grid = [
7+
["1","1","1","1","0"],
8+
["1","1","0","1","0"],
9+
["1","1","0","0","0"],
10+
["0","0","0","0","0"]
11+
]
12+
self.assertEqual(Solution().numIslands(grid), 1)
13+
14+
def test_numIslands2(self):
15+
grid = [
16+
["1","1","0","0","0"],
17+
["1","1","0","0","0"],
18+
["0","0","1","0","0"],
19+
["0","0","0","1","1"]
20+
]
21+
self.assertEqual(Solution().numIslands(grid), 3)

src/main/python/g0201_0300/s0206_reverse_linked_list/Solution0206.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# #Algorithm_I_Day_10_Recursion_Backtracking #Level_1_Day_3_Linked_List #Udemy_Linked_List
44
# #Big_O_Time_O(N)_Space_O(1) #2025_07_25_Time_0_ms_(100.00%)_Space_18.75_MB_(37.87%)
55

6+
from typing import Optional
7+
8+
class ListNode:
9+
def __init__(self, val=0, next=None):
10+
self.val = val
11+
self.next = next
12+
613
# Definition for singly-linked list.
714
# class ListNode:
815
# def __init__(self, val=0, next=None):
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import unittest
2+
from Solution0206 import Solution, ListNode
3+
4+
def from_list(values):
5+
dummy = ListNode(0)
6+
curr = dummy
7+
for v in values:
8+
curr.next = ListNode(v)
9+
curr = curr.next
10+
return dummy.next
11+
12+
def to_list(head):
13+
result = []
14+
curr = head
15+
while curr is not None:
16+
result.append(curr.val)
17+
curr = curr.next
18+
return result
19+
20+
class SolutionTest(unittest.TestCase):
21+
def test_reverseList(self):
22+
head = from_list([1,2,3,4,5])
23+
result = Solution().reverseList(head)
24+
self.assertEqual(to_list(result), [5,4,3,2,1])
25+
26+
def test_reverseList2(self):
27+
head = from_list([1,2])
28+
result = Solution().reverseList(head)
29+
self.assertEqual(to_list(result), [2,1])
30+
31+
def test_reverseList3(self):
32+
head = from_list([])
33+
result = Solution().reverseList(head)
34+
self.assertEqual(to_list(result), [])

src/main/python/g0201_0300/s0207_course_schedule/Solution0207.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# #Breadth_First_Search #Graph #Topological_Sort #Top_Interview_150_Graph_General
33
# #Big_O_Time_O(N)_Space_O(N) #2025_07_25_Time_3_ms_(88.23%)_Space_19.05_MB_(73.39%)
44

5+
from typing import List
6+
57
class Solution:
68
WHITE = 0
79
GRAY = 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0207 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_canFinish(self):
6+
self.assertTrue(Solution().canFinish(2, [[1,0]]))
7+
8+
def test_canFinish2(self):
9+
self.assertFalse(Solution().canFinish(2, [[1,0],[0,1]]))
10+
11+
def test_canFinish3(self):
12+
self.assertTrue(Solution().canFinish(1, []))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Trie import Trie
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_trie(self):
6+
trie = Trie()
7+
trie.insert("apple")
8+
self.assertTrue(trie.search("apple"))
9+
self.assertFalse(trie.search("app"))
10+
self.assertTrue(trie.startsWith("app"))
11+
trie.insert("app")
12+
self.assertTrue(trie.search("app"))

src/main/python/g0201_0300/s0215_kth_largest_element_in_an_array/Solution0215.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# #Data_Structure_II_Day_20_Heap_Priority_Queue #Top_Interview_150_Heap
44
# #Big_O_Time_O(n*log(n))_Space_O(log(n)) #2025_07_25_Time_45_ms_(90.46%)_Space_28.73_MB_(45.18%)
55

6+
from typing import List
7+
68
class Solution:
79
def findKthLargest(self, nums: List[int], k: int) -> int:
810
nums.sort()

0 commit comments

Comments
 (0)