From bcb60aac8ae58a6b39f968978f53f15ec182e9fa Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 31 Jul 2026 22:31:21 +0900 Subject: [PATCH 1/7] valid parentheses solution --- valid-parentheses/yuseok89.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 valid-parentheses/yuseok89.py diff --git a/valid-parentheses/yuseok89.py b/valid-parentheses/yuseok89.py new file mode 100644 index 0000000000..2c3e54454a --- /dev/null +++ b/valid-parentheses/yuseok89.py @@ -0,0 +1,16 @@ +# TC: O(N) +# SC: O(N/2) +class Solution: + def isValid(self, s: str) -> bool: + pars = {'(': ')', '{': '}', '[': ']'} + stack = [] + + for c in s: + if c in pars: + stack.append(c) + else: + if len(stack) == 0 or pars.get(stack.pop(), '') != c: + return False + + return len(stack) == 0 + From e5e9478c2acd12fe261d2437426a86378942f5e1 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 31 Jul 2026 22:41:15 +0900 Subject: [PATCH 2/7] container with most water solution --- container-with-most-water/yuseok89.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 container-with-most-water/yuseok89.py diff --git a/container-with-most-water/yuseok89.py b/container-with-most-water/yuseok89.py new file mode 100644 index 0000000000..1e275abc76 --- /dev/null +++ b/container-with-most-water/yuseok89.py @@ -0,0 +1,22 @@ +# TC: O(N) +# SC: O(1) +class Solution: + def maxArea(self, height: List[int]) -> int: + l = 0 + r = len(height) - 1 + max_height = max(height) + ans = 0 + + while l < r: + ans = max(ans, min(height[l], height[r]) * (r - l)) + + if ans > max_height * (r - l): + return ans + + if height[l] < height[r]: + l += 1 + else: + r -= 1 + + return ans; + From aebb139ca005aa0514724bf5dbd0e4a0fe30683b Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 31 Jul 2026 22:43:12 +0900 Subject: [PATCH 3/7] design add and search words data structure solution --- .../yuseok89.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 design-add-and-search-words-data-structure/yuseok89.py diff --git a/design-add-and-search-words-data-structure/yuseok89.py b/design-add-and-search-words-data-structure/yuseok89.py new file mode 100644 index 0000000000..affc0fe3d0 --- /dev/null +++ b/design-add-and-search-words-data-structure/yuseok89.py @@ -0,0 +1,43 @@ +class WordDictionary: + + def __init__(self): + self.trie = {} + + def addWord(self, word: str) -> None: + cur = self.trie + + for c in word: + if c not in cur: + cur[c] = {} + cur = cur[c] + + cur[0] = True + + def search(self, word: str) -> bool: + + n = len(word) + + def rec(cur, idx): + if idx == n: + return 0 in cur + + if word[idx] == '.': + for next in cur: + if next == 0: + continue + if rec(cur[next], idx + 1): + return True + return False + else: + if word[idx] in cur: + return rec(cur[word[idx]], idx + 1) + else: + return False + + return rec(self.trie, 0) + +# Your WordDictionary object will be instantiated and called as such: +# obj = WordDictionary() +# obj.addWord(word) +# param_2 = obj.search(word) + From 8ea4676c25d3f63e560c4e9d35465ec2c108a71e Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 31 Jul 2026 22:44:18 +0900 Subject: [PATCH 4/7] longest increasing subsequence solution --- longest-increasing-subsequence/yuseok89.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 longest-increasing-subsequence/yuseok89.py diff --git a/longest-increasing-subsequence/yuseok89.py b/longest-increasing-subsequence/yuseok89.py new file mode 100644 index 0000000000..1493180e19 --- /dev/null +++ b/longest-increasing-subsequence/yuseok89.py @@ -0,0 +1,15 @@ +# TC: O(NlogN) +# SC: O(N) +class Solution: + def lengthOfLIS(self, nums: List[int]) -> int: + arr = [] + + for num in nums: + if len(arr) == 0 or arr[-1] < num: + arr.append(num) + else: + idx = bisect_left(arr, num) + arr[idx] = num + + return len(arr) + From e7fc5a3d6d3a1ec68d19fcb2f9aa50c9d4efec2f Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 31 Jul 2026 22:45:38 +0900 Subject: [PATCH 5/7] spiral matrix solution --- spiral-matrix/yuseok89.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spiral-matrix/yuseok89.py diff --git a/spiral-matrix/yuseok89.py b/spiral-matrix/yuseok89.py new file mode 100644 index 0000000000..06c9f827f0 --- /dev/null +++ b/spiral-matrix/yuseok89.py @@ -0,0 +1,26 @@ +# TC: O(N*M) +# SC: O(N*M) +class Solution: + def spiralOrder(self, matrix: List[List[int]]) -> List[int]: + n = len(matrix) + m = len(matrix[0]) + ans = [] + row, col, dir = 0, -1, 1 + + n -= 1 + + while n >= 0 and m >= 1: + for i in range(0, m): + col += dir + ans.append(matrix[row][col]) + + for i in range(0, n): + row += dir + ans.append(matrix[row][col]) + + n -= 1 + m -= 1 + dir *= -1 + + return ans; + From b32fb5cff75a4f17d0baeec5d21f86f1f2b011b3 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 31 Jul 2026 22:47:52 +0900 Subject: [PATCH 6/7] remove unnecessary comments --- design-add-and-search-words-data-structure/yuseok89.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/design-add-and-search-words-data-structure/yuseok89.py b/design-add-and-search-words-data-structure/yuseok89.py index affc0fe3d0..81c0479c59 100644 --- a/design-add-and-search-words-data-structure/yuseok89.py +++ b/design-add-and-search-words-data-structure/yuseok89.py @@ -36,8 +36,3 @@ def rec(cur, idx): return rec(self.trie, 0) -# Your WordDictionary object will be instantiated and called as such: -# obj = WordDictionary() -# obj.addWord(word) -# param_2 = obj.search(word) - From e1718c937aecece3f6f3e18f8de1c5ec804a6043 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Sat, 1 Aug 2026 19:21:32 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=EB=A6=AC=EB=B7=B0=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- container-with-most-water/yuseok89.py | 2 +- design-add-and-search-words-data-structure/yuseok89.py | 2 +- valid-parentheses/yuseok89.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/container-with-most-water/yuseok89.py b/container-with-most-water/yuseok89.py index 1e275abc76..2938344e63 100644 --- a/container-with-most-water/yuseok89.py +++ b/container-with-most-water/yuseok89.py @@ -18,5 +18,5 @@ def maxArea(self, height: List[int]) -> int: else: r -= 1 - return ans; + return ans diff --git a/design-add-and-search-words-data-structure/yuseok89.py b/design-add-and-search-words-data-structure/yuseok89.py index 81c0479c59..c7989240f3 100644 --- a/design-add-and-search-words-data-structure/yuseok89.py +++ b/design-add-and-search-words-data-structure/yuseok89.py @@ -17,7 +17,7 @@ def search(self, word: str) -> bool: n = len(word) - def rec(cur, idx): + def rec(cur: dict, idx: int) -> bool: if idx == n: return 0 in cur diff --git a/valid-parentheses/yuseok89.py b/valid-parentheses/yuseok89.py index 2c3e54454a..fffc7ebeb4 100644 --- a/valid-parentheses/yuseok89.py +++ b/valid-parentheses/yuseok89.py @@ -1,5 +1,5 @@ # TC: O(N) -# SC: O(N/2) +# SC: O(N) class Solution: def isValid(self, s: str) -> bool: pars = {'(': ')', '{': '}', '[': ']'} @@ -9,7 +9,7 @@ def isValid(self, s: str) -> bool: if c in pars: stack.append(c) else: - if len(stack) == 0 or pars.get(stack.pop(), '') != c: + if not stack or pars[stack.pop()] != c: return False return len(stack) == 0