Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added tests 236-394#67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javadev merged 2 commits intoLeetCode-in-Python:mainfromjscrdev:tests-236-394
Sep 23, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
import unittest
from Solution0006 import Solution

class SolutionTest(unittest.TestCase):
def test_convert(self):
self.assertEqual(Solution().convert("PAYPALISHIRING", 3), "PAHNAPLSIIGYIR")

def test_convert2(self):
self.assertEqual(Solution().convert("PAYPALISHIRING", 4), "PINALSIGYAHRPI")
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,12 @@
# #Top_Interview_150_Binary_Tree_General #Big_O_Time_O(n)_Space_O(n)
# #2025_07_25_Time_41_ms_(97.74%)_Space_22.14_MB_(43.54%)

class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right

# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
Expand Down
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
import unittest
from Solution0236 import Solution, TreeNode

class SolutionTest(unittest.TestCase):
def test_lowestCommonAncestor(self):
leftNodeLeftNode = TreeNode(6)
leftNodeRightNode = TreeNode(2, TreeNode(7), TreeNode(4))
leftNode = TreeNode(5, leftNodeLeftNode, leftNodeRightNode)
rightNode = TreeNode(1, TreeNode(0), TreeNode(8))
root = TreeNode(3, leftNode, rightNode)
self.assertEqual(
Solution().lowestCommonAncestor(root, TreeNode(5), TreeNode(1)).val,
3
)

def test_lowestCommonAncestor2(self):
leftNodeLeftNode = TreeNode(6)
leftNodeRightNode = TreeNode(2, TreeNode(7), TreeNode(4))
leftNode = TreeNode(5, leftNodeLeftNode, leftNodeRightNode)
rightNode = TreeNode(1, TreeNode(0), TreeNode(8))
root = TreeNode(3, leftNode, rightNode)
self.assertEqual(
Solution().lowestCommonAncestor(root, TreeNode(5), TreeNode(4)).val,
5
)

def test_lowestCommonAncestor3(self):
root = TreeNode(2, TreeNode(1), None)
self.assertEqual(
Solution().lowestCommonAncestor(root, TreeNode(2), TreeNode(1)).val,
2
)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
# #Data_Structure_II_Day_5_Array #Udemy_Arrays #Top_Interview_150_Array/String
# #Big_O_Time_O(n^2)_Space_O(n) #2025_07_25_Time_15_ms_(97.12%)_Space_23.25_MB_(79.77%)

from typing import List

class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
product = 1
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import unittest
from Solution0238 import Solution

class SolutionTest(unittest.TestCase):
def test_productExceptSelf(self):
self.assertEqual(
Solution().productExceptSelf([1, 2, 3, 4]),
[24, 12, 8, 6]
)

def test_productExceptSelf2(self):
self.assertEqual(
Solution().productExceptSelf([-1, 1, 0, -3, 3]),
[0, 0, 9, 0, 0]
)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,9 @@
# #Monotonic_Queue #Udemy_Arrays #Big_O_Time_O(n*k)_Space_O(n+k)
# #2025_07_25_Time_152_ms_(81.96%)_Space_30.79_MB_(96.65%)

from typing import List
from collections import deque

class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
q = deque()
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import unittest
from Solution0239 import Solution

class SolutionTest(unittest.TestCase):
def test_maxSlidingWindow(self):
self.assertEqual(
Solution().maxSlidingWindow([1, 3, -1, -3, 5, 3, 6, 7], 3),
[3, 3, 5, 5, 6, 7]
)

def test_maxSlidingWindow2(self):
self.assertEqual(
Solution().maxSlidingWindow([1], 1),
[1]
)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
# #Data_Structure_II_Day_4_Array #Binary_Search_II_Day_8 #Big_O_Time_O(n+m)_Space_O(1)
# #2025_07_25_Time_143_ms_(64.84%)_Space_24.00_MB_(80.86%)

from typing import List

class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
if not matrix or not matrix[0]:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
import unittest
from Solution0240 import Solution

class SolutionTest(unittest.TestCase):
def test_searchMatrix(self):
matrix = [
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]
self.assertEqual(Solution().searchMatrix(matrix, 5), True)

def test_searchMatrix2(self):
matrix = [
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]
self.assertEqual(Solution().searchMatrix(matrix, 20), False)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
# #Algorithm_I_Day_3_Two_Pointers #Programming_Skills_I_Day_6_Array #Udemy_Arrays
# #Big_O_Time_O(n)_Space_O(1) #2025_07_25_Time_3_ms_(80.05%)_Space_18.63_MB_(94.75%)

from typing import List

class Solution:
def moveZeroes(self, nums: List[int]) -> None:
"""
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
import unittest
from Solution0283 import Solution

class SolutionTest(unittest.TestCase):
def test_moveZeroes(self):
array = [0, 1, 0, 3, 12]
Solution().moveZeroes(array)
self.assertEqual(array, [1, 3, 12, 0, 0])

def test_moveZeroes2(self):
array = [0]
Solution().moveZeroes(array)
self.assertEqual(array, [0])
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
# #Binary_Search_II_Day_5 #Big_O_Time_O(n)_Space_O(n)
# #2025_07_25_Time_16_ms_(96.25%)_Space_30.09_MB_(49.05%)

from typing import List

class Solution:
def findDuplicate(self, nums: List[int]) -> int:
arr = [0] * (len(nums) + 1)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import unittest
from Solution0287 import Solution

class SolutionTest(unittest.TestCase):
def test_findDuplicate(self):
self.assertEqual(Solution().findDuplicate([1, 3, 4, 2, 2]), 2)

def test_findDuplicate2(self):
self.assertEqual(Solution().findDuplicate([3, 1, 3, 4, 2]), 3)

def test_findDuplicate3(self):
self.assertEqual(Solution().findDuplicate([1, 1]), 1)

def test_findDuplicate4(self):
self.assertEqual(Solution().findDuplicate([1, 1, 2]), 1)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
# #Top_Interview_150_Heap #Big_O_Time_O(n*log_n)_Space_O(n)
# #2025_07_25_Time_131_ms_(72.46%)_Space_40.10_MB_(17.67%)

from typing import List

import heapq

class MedianFinder:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
import unittest
from MedianFinder import MedianFinder

class MedianFinderTest(unittest.TestCase):
def test_medianFinder(self):
medianFinder = MedianFinder()
medianFinder.addNum(1)
medianFinder.addNum(2)
self.assertEqual(medianFinder.findMedian(), 1.5)
medianFinder.addNum(3)
self.assertEqual(medianFinder.findMedian(), 2.0)

def test_medianFinder2(self):
medianFinder = MedianFinder()
medianFinder.addNum(1)
medianFinder.addNum(3)
medianFinder.addNum(-1)
self.assertEqual(medianFinder.findMedian(), 1.0)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@
# #Udemy_Dynamic_Programming #Top_Interview_150_1D_DP #Big_O_Time_O(n*log_n)_Space_O(n)
# #2025_07_25_Time_11_ms_(78.54%)_Space_18.12_MB_(38.75%)

from typing import List
import bisect

class Solution:
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import unittest
from Solution0300 import Solution

class SolutionTest(unittest.TestCase):
def test_lengthOfLIS(self):
self.assertEqual(Solution().lengthOfLIS([10, 9, 2, 5, 3, 7, 101, 18]), 4)

def test_lengthOfLIS2(self):
self.assertEqual(Solution().lengthOfLIS([0, 1, 0, 3, 2, 3]), 4)

def test_lengthOfLIS3(self):
self.assertEqual(Solution().lengthOfLIS([7, 7, 7, 7, 7, 7, 7]), 1)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,8 @@
# #Level_2_Day_12_Dynamic_Programming #Top_Interview_150_1D_DP #Big_O_Time_O(m*n)_Space_O(amount)
# #2025_07_25_Time_454_ms_(96.33%)_Space_18.19_MB_(69.69%)

from typing import List

class Solution:
def coinChange(self, coins: List[int], amount: int) -> int:
dp = [0] * (amount + 1)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
import unittest
from Solution0322 import Solution

class SolutionTest(unittest.TestCase):
def test_coinChange(self):
self.assertEqual(Solution().coinChange([1, 2, 5], 11), 3)

def test_coinChange2(self):
self.assertEqual(Solution().coinChange([2], 3), -1)

def test_coinChange3(self):
self.assertEqual(Solution().coinChange([1], 0), 0)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
# #Udemy_Bit_Manipulation #Big_O_Time_O(num)_Space_O(num)
# #2025_07_25_Time_3_ms_(94.51%)_Space_18.68_MB_(22.83%)

from typing import List

class Solution:
def countBits(self, num: int) -> List[int]:
result = [0] * (num + 1)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
import unittest
from Solution0338 import Solution

class SolutionTest(unittest.TestCase):
def test_countBits(self):
self.assertEqual(Solution().countBits(2), [0, 1, 1])

def test_countBits2(self):
self.assertEqual(Solution().countBits(5), [0, 1, 1, 2, 1, 2])
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@
# #Divide_and_Conquer #Quickselect #Bucket_Sort #Data_Structure_II_Day_20_Heap_Priority_Queue
# #Big_O_Time_O(n*log(n))_Space_O(k) #2025_07_25_Time_4_ms_(69.79%)_Space_21.51_MB_(27.28%)

from typing import List
import heapq
from collections import Counter

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import unittest
from Solution0347 import Solution

class SolutionTest(unittest.TestCase):
def test_topKFrequent(self):
self.assertEqual(
Solution().topKFrequent([1, 1, 1, 2, 2, 3], 2),
[1, 2]
)

def test_topKFrequent2(self):
self.assertEqual(
Solution().topKFrequent([1], 1),
[1]
)
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
import unittest
from Solution0394 import Solution

class SolutionTest(unittest.TestCase):
def test_decodeString(self):
self.assertEqual(Solution().decodeString("3[a]2[bc]"), "aaabcbc")

def test_decodeString2(self):
self.assertEqual(Solution().decodeString("3[a2[c]]"), "accaccacc")

def test_decodeString3(self):
self.assertEqual(Solution().decodeString("2[abc]3[cd]ef"), "abcabccdcdcdef")

def test_decodeString4(self):
self.assertEqual(Solution().decodeString("abc3[cd]xyz"), "abccdcdcdxyz")

[8]ページ先頭

©2009-2025 Movatter.jp