Skip to content

Commit 89650e2

Browse files
authored
Added tests 236-394
1 parent 7d1ed56 commit 89650e2

File tree

24 files changed

+228
-0
lines changed

24 files changed

+228
-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 Solution0006 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_convert(self):
6+
self.assertEqual(Solution().convert("PAYPALISHIRING", 3), "PAHNAPLSIIGYIR")
7+
8+
def test_convert2(self):
9+
self.assertEqual(Solution().convert("PAYPALISHIRING", 4), "PINALSIGYAHRPI")

src/main/python/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/Solution0236.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
# #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n)
44
# #2025_07_25_Time_41_ms_(97.74%)_Space_22.14_MB_(43.54%)
55

6+
class TreeNode:
7+
def __init__(self, val=0, left=None, right=None):
8+
self.val = val
9+
self.left = left
10+
self.right = right
11+
612
# Definition for a binary tree node.
713
# class TreeNode:
814
# def __init__(self, x):
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
from Solution0236 import Solution, TreeNode
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_lowestCommonAncestor(self):
6+
leftNodeLeftNode = TreeNode(6)
7+
leftNodeRightNode = TreeNode(2, TreeNode(7), TreeNode(4))
8+
leftNode = TreeNode(5, leftNodeLeftNode, leftNodeRightNode)
9+
rightNode = TreeNode(1, TreeNode(0), TreeNode(8))
10+
root = TreeNode(3, leftNode, rightNode)
11+
self.assertEqual(
12+
Solution().lowestCommonAncestor(root, TreeNode(5), TreeNode(1)).val,
13+
3
14+
)
15+
16+
def test_lowestCommonAncestor2(self):
17+
leftNodeLeftNode = TreeNode(6)
18+
leftNodeRightNode = TreeNode(2, TreeNode(7), TreeNode(4))
19+
leftNode = TreeNode(5, leftNodeLeftNode, leftNodeRightNode)
20+
rightNode = TreeNode(1, TreeNode(0), TreeNode(8))
21+
root = TreeNode(3, leftNode, rightNode)
22+
self.assertEqual(
23+
Solution().lowestCommonAncestor(root, TreeNode(5), TreeNode(4)).val,
24+
5
25+
)
26+
27+
def test_lowestCommonAncestor3(self):
28+
root = TreeNode(2, TreeNode(1), None)
29+
self.assertEqual(
30+
Solution().lowestCommonAncestor(root, TreeNode(2), TreeNode(1)).val,
31+
2
32+
)

src/main/python/g0201_0300/s0238_product_of_array_except_self/Solution0238.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# #Data_Structure_II_Day_5_Array #Udemy_Arrays #Top_Interview_150_Array/String
33
# #Big_O_Time_O(n^2)_Space_O(n) #2025_07_25_Time_15_ms_(97.12%)_Space_23.25_MB_(79.77%)
44

5+
from typing import List
6+
57
class Solution:
68
def productExceptSelf(self, nums: List[int]) -> List[int]:
79
product = 1
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import unittest
2+
from Solution0238 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_productExceptSelf(self):
6+
self.assertEqual(
7+
Solution().productExceptSelf([1, 2, 3, 4]),
8+
[24, 12, 8, 6]
9+
)
10+
11+
def test_productExceptSelf2(self):
12+
self.assertEqual(
13+
Solution().productExceptSelf([-1, 1, 0, -3, 3]),
14+
[0, 0, 9, 0, 0]
15+
)

src/main/python/g0201_0300/s0239_sliding_window_maximum/Solution0239.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k)
33
# #2025_07_25_Time_152_ms_(81.96%)_Space_30.79_MB_(96.65%)
44

5+
from typing import List
6+
from collections import deque
7+
58
class Solution:
69
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
710
q = deque()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import unittest
2+
from Solution0239 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_maxSlidingWindow(self):
6+
self.assertEqual(
7+
Solution().maxSlidingWindow([1, 3, -1, -3, 5, 3, 6, 7], 3),
8+
[3, 3, 5, 5, 6, 7]
9+
)
10+
11+
def test_maxSlidingWindow2(self):
12+
self.assertEqual(
13+
Solution().maxSlidingWindow([1], 1),
14+
[1]
15+
)

src/main/python/g0201_0300/s0240_search_a_2d_matrix_ii/Solution0240.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 #Big_O_Time_O(n+m)_Space_O(1)
33
# #2025_07_25_Time_143_ms_(64.84%)_Space_24.00_MB_(80.86%)
44

5+
from typing import List
6+
57
class Solution:
68
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
79
if not matrix or not matrix[0]:
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
from Solution0240 import Solution
3+
4+
class SolutionTest(unittest.TestCase):
5+
def test_searchMatrix(self):
6+
matrix = [
7+
[1, 4, 7, 11, 15],
8+
[2, 5, 8, 12, 19],
9+
[3, 6, 9, 16, 22],
10+
[10, 13, 14, 17, 24],
11+
[18, 21, 23, 26, 30]
12+
]
13+
self.assertEqual(Solution().searchMatrix(matrix, 5), True)
14+
15+
def test_searchMatrix2(self):
16+
matrix = [
17+
[1, 4, 7, 11, 15],
18+
[2, 5, 8, 12, 19],
19+
[3, 6, 9, 16, 22],
20+
[10, 13, 14, 17, 24],
21+
[18, 21, 23, 26, 30]
22+
]
23+
self.assertEqual(Solution().searchMatrix(matrix, 20), False)

src/main/python/g0201_0300/s0283_move_zeroes/Solution0283.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# #Algorithm_I_Day_3_Two_Pointers #Programming_Skills_I_Day_6_Array #Udemy_Arrays
33
# #Big_O_Time_O(n)_Space_O(1) #2025_07_25_Time_3_ms_(80.05%)_Space_18.63_MB_(94.75%)
44

5+
from typing import List
6+
57
class Solution:
68
def moveZeroes(self, nums: List[int]) -> None:
79
"""

0 commit comments

Comments
 (0)