Skip to content

Commit e7f8e94

Browse files
authored
Added tests 75-102
1 parent 8e0c7a5 commit e7f8e94

File tree

18 files changed

+260
-1
lines changed

18 files changed

+260
-1
lines changed

src/main/python/g0001_0100/s0075_sort_colors/Solution0075.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# #Data_Structure_II_Day_2_Array #Udemy_Arrays #Big_O_Time_O(n)_Space_O(1)
33
# #2025_07_24_Time_0_ms_(100.00%)_Space_17.89_MB_(33.05%)
44

5+
from typing import List
6+
57
class Solution:
68
def sortColors(self, nums: List[int]) -> None:
79
"""
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
from Solution0075 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_sortColors(self):
6+
nums = [2,0,2,1,1,0]
7+
Solution().sortColors(nums)
8+
self.assertEqual(nums, [0,0,1,1,2,2])
9+
10+
def test_sortColors2(self):
11+
nums = [2,0,1]
12+
Solution().sortColors(nums)
13+
self.assertEqual(nums, [0,1,2])
14+
15+
def test_sortColors3(self):
16+
nums = [0]
17+
Solution().sortColors(nums)
18+
self.assertEqual(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 Solution0076 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_minWindow(self):
6+
self.assertEqual(Solution().minWindow("ADOBECODEBANC", "ABC"), "BANC")
7+
8+
def test_minWindow2(self):
9+
self.assertEqual(Solution().minWindow("a", "a"), "a")
10+
11+
def test_minWindow3(self):
12+
self.assertEqual(Solution().minWindow("a", "aa"), "")

src/main/python/g0001_0100/s0078_subsets/Solution0078.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# #Big_O_Time_O(2^n)_Space_O(n*2^n) #2025_07_24_Time_0_ms_(100.00%)_Space_18.05_MB_(21.18%)
44

55
from itertools import combinations
6+
from typing import List
67

78
class Solution:
89
def subsets(self, nums: List[int]) -> List[List[int]]:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import unittest
2+
from Solution0078 import Solution
3+
4+
def sort_nested(lists):
5+
return sorted([sorted(x) for x in lists])
6+
7+
class SolutionTest(unittest.TestCase):
8+
def test_subsets(self):
9+
res = Solution().subsets([1,2,3])
10+
expected = [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
11+
self.assertEqual(sort_nested(res), sort_nested(expected))
12+
13+
def test_subsets2(self):
14+
res = Solution().subsets([0])
15+
expected = [[],[0]]
16+
self.assertEqual(sort_nested(res), sort_nested(expected))

src/main/python/g0001_0100/s0079_word_search/Solution0079.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# #Algorithm_II_Day_11_Recursion_Backtracking #Top_Interview_150_Backtracking
33
# #Big_O_Time_O(4^(m*n))_Space_O(m*n) #2025_07_24_Time_623_ms_(94.85%)_Space_17.84_MB_(65.07%)
44

5+
from typing import List
6+
from collections import Counter
7+
58
class Solution:
69
def exist(self, board: List[List[str]], word: str) -> bool:
710
n = len(board)
@@ -15,7 +18,8 @@ def is_sub(board, word):
1518
c = Counter()
1619
for line in board:
1720
c.update(line)
18-
return Counter(word) <= c
21+
w = Counter(word)
22+
return all(c[ch] >= count for ch, count in w.items())
1923

2024
if not is_sub(board, word):
2125
return False
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import unittest
2+
from Solution0079 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_exist(self):
6+
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]
7+
self.assertTrue(Solution().exist(board, "ABCCED"))
8+
9+
def test_exist2(self):
10+
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]
11+
self.assertTrue(Solution().exist(board, "SEE"))
12+
13+
def test_exist3(self):
14+
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]]
15+
self.assertFalse(Solution().exist(board, "ABCB"))

src/main/python/g0001_0100/s0084_largest_rectangle_in_histogram/Solution0084.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Stack #Monotonic_Stack
22
# #Big_O_Time_O(n_log_n)_Space_O(log_n) #2025_07_24_Time_63_ms_(99.53%)_Space_29.12_MB_(95.20%)
33

4+
from typing import List
5+
46
class Solution:
57
def largestRectangleArea(self, heights: List[int]) -> int:
68
lefts = [0]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0084 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_largestRectangleArea(self):
6+
self.assertEqual(Solution().largestRectangleArea([2,1,5,6,2,3]), 10)
7+
8+
def test_largestRectangleArea2(self):
9+
self.assertEqual(Solution().largestRectangleArea([2,4]), 4)
10+
11+
def test_largestRectangleArea3(self):
12+
self.assertEqual(Solution().largestRectangleArea([1]), 1)

src/main/python/g0001_0100/s0094_binary_tree_inorder_traversal/Solution0094.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
# #Stack #Data_Structure_I_Day_10_Tree #Udemy_Tree_Stack_Queue #Big_O_Time_O(n)_Space_O(n)
33
# #2025_07_24_Time_0_ms_(100.00%)_Space_17.90_MB_(12.04%)
44

5+
from typing import Optional, List
6+
7+
class TreeNode:
8+
def __init__(self, val=0, left=None, right=None):
9+
self.val = val
10+
self.left = left
11+
self.right = right
12+
513
# Definition for a binary tree node.
614
# class TreeNode:
715
# def __init__(self, val=0, left=None, right=None):

0 commit comments

Comments
 (0)