Skip to content

Commit c094347

Browse files
authored
Added tests 32-48
1 parent a69f5cd commit c094347

File tree

19 files changed

+148
-0
lines changed

19 files changed

+148
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import unittest
2+
from Solution0032 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_longestValidParentheses(self):
6+
self.assertEqual(Solution().longestValidParentheses("(()"), 2)
7+
8+
def test_longestValidParentheses2(self):
9+
self.assertEqual(Solution().longestValidParentheses(")()())"), 4)

src/main/python/g0001_0100/s0033_search_in_rotated_sorted_array/Solution0033.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# #Udemy_Binary_Search #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1)
44
# #2025_07_22_Time_0_ms_(100.00%)_Space_18.28_MB_(22.25%)
55

6+
from typing import List
7+
68
class Solution:
79
def search(self, nums: List[int], target: int) -> int:
810
lo, hi = 0, len(nums) - 1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0033 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_search(self):
6+
self.assertEqual(Solution().search([4,5,6,7,0,1,2], 0), 4)
7+
8+
def test_search2(self):
9+
self.assertEqual(Solution().search([4,5,6,7,0,1,2], 3), -1)
10+
11+
def test_search3(self):
12+
self.assertEqual(Solution().search([1], 0), -1)

src/main/python/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/Solution0034.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# #Algorithm_II_Day_1_Binary_Search #Binary_Search_I_Day_5 #Top_Interview_150_Binary_Search
33
# #Big_O_Time_O(log_n)_Space_O(1) #2025_07_22_Time_0_ms_(100.00%)_Space_18.99_MB_(75.63%)
44

5+
from typing import List
6+
57
class Solution:
68
def searchRange(self, nums: List[int], target: int) -> List[int]:
79
ans = [-1, -1]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unittest
2+
from Solution0034 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_searchRange(self):
6+
self.assertEqual(Solution().searchRange([5,7,7,8,8,10], 8), [3, 4])
7+
8+
def test_searchRange2(self):
9+
self.assertEqual(Solution().searchRange([5,7,7,8,8,10], 6), [-1, -1])
10+
11+
def test_searchRange3(self):
12+
self.assertEqual(Solution().searchRange([], 0), [-1, -1])

src/main/python/g0001_0100/s0035_search_insert_position/Solution0035.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# #Binary_Search_I_Day_2 #Top_Interview_150_Binary_Search #Big_O_Time_O(log_n)_Space_O(1)
33
# #2025_07_22_Time_0_ms_(100.00%)_Space_18.46_MB_(43.50%)
44

5+
from typing import List
6+
57
class Solution:
68
def searchInsert(self, nums: List[int], target: int) -> int:
79
low = 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import unittest
2+
from Solution0035 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_searchInsert(self):
6+
self.assertEqual(Solution().searchInsert([1,3,5,6], 5), 2)
7+
8+
def test_searchInsert2(self):
9+
self.assertEqual(Solution().searchInsert([1,3,5,6], 2), 1)
10+
11+
def test_searchInsert3(self):
12+
self.assertEqual(Solution().searchInsert([1,3,5,6], 7), 4)
13+
14+
def test_searchInsert4(self):
15+
self.assertEqual(Solution().searchInsert([1,3,5,6], 0), 0)

src/main/python/g0001_0100/s0039_combination_sum/Solution0039.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# #Top_Interview_150_Backtracking #Big_O_Time_O(2^n)_Space_O(n+2^n)
44
# #2025_07_22_Time_4_ms_(90.51%)_Space_17.64_MB_(98.10%)
55

6+
from typing import List
7+
68
class Solution:
79
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
810
ans = []
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
from Solution0039 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_combinationSum(self):
9+
res = Solution().combinationSum([2,3,6,7], 7)
10+
self.assertEqual(sort_nested(res), sort_nested([[7],[2,2,3]]))
11+
12+
def test_combinationSum2(self):
13+
res = Solution().combinationSum([2,3,5], 8)
14+
self.assertEqual(sort_nested(res), sort_nested([[2,2,2,2],[2,3,3],[3,5]]))
15+
16+
def test_combinationSum3(self):
17+
res = Solution().combinationSum([2], 1)
18+
self.assertEqual(sort_nested(res), sort_nested([]))

src/main/python/g0001_0100/s0041_first_missing_positive/Solution0041.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 #Hash_Table #Udemy_Arrays
22
# #Big_O_Time_O(n)_Space_O(n) #2025_07_24_Time_19_ms_(93.81%)_Space_34.68_MB_(19.66%)
33

4+
from typing import List
5+
46
class Solution:
57
def firstMissingPositive(self, nums: List[int]) -> int:
68
counter = 1

0 commit comments

Comments
 (0)