From 4836151a04615e19e30bc88bca1deb359467b662 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 23 Jun 2026 22:50:15 +0900 Subject: [PATCH 01/26] contains duplicate solution --- contains-duplicate/yuseok89.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 contains-duplicate/yuseok89.py diff --git a/contains-duplicate/yuseok89.py b/contains-duplicate/yuseok89.py new file mode 100644 index 0000000000..8648095834 --- /dev/null +++ b/contains-duplicate/yuseok89.py @@ -0,0 +1,11 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + dup_check = set() + + for num in nums: + if num in dup_check: + return True + + dup_check.add(num) + + return False From cdc00da1eda0b122b45a94b8800d06edb786024b Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 23 Jun 2026 22:51:51 +0900 Subject: [PATCH 02/26] two sum solution --- two-sum/yuseok89.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 two-sum/yuseok89.py diff --git a/two-sum/yuseok89.py b/two-sum/yuseok89.py new file mode 100644 index 0000000000..2033711307 --- /dev/null +++ b/two-sum/yuseok89.py @@ -0,0 +1,14 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + idx_map = {} + + for idx, num in enumerate(nums): + idx_map[num] = idx + + for idx, num in enumerate(nums): + need = target - num + + if need in idx_map and idx != idx_map[need]: + return [idx, idx_map[need]] + + return [] From cc0a988332934a6eb50e471feac5e726b5fd7cd6 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 23 Jun 2026 22:54:01 +0900 Subject: [PATCH 03/26] top k frequent elements solution --- top-k-frequent-elements/yuseok89.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 top-k-frequent-elements/yuseok89.py diff --git a/top-k-frequent-elements/yuseok89.py b/top-k-frequent-elements/yuseok89.py new file mode 100644 index 0000000000..bfaa5de681 --- /dev/null +++ b/top-k-frequent-elements/yuseok89.py @@ -0,0 +1,28 @@ +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + + import heapq + + heap = [] + cnt = {} + + for num in nums: + if num not in cnt: + cnt[num] = 0 + + cnt[num] = cnt[num] + 1 + + for num in cnt.keys(): + if len(heap) < k: + heapq.heappush(heap, cnt[num]) + elif heap[0] < cnt[num]: + heapq.heappop(heap) + heapq.heappush(heap, cnt[num]) + + ret = [] + + for num in cnt.keys(): + if cnt[num] >= heap[0]: + ret.append(num) + + return ret From c894055dfd11492cecaff47fcc0a2e3c2ce6faf4 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 23 Jun 2026 22:55:18 +0900 Subject: [PATCH 04/26] longest consecutive sequence solution --- longest-consecutive-sequence/yuseok89.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 longest-consecutive-sequence/yuseok89.py diff --git a/longest-consecutive-sequence/yuseok89.py b/longest-consecutive-sequence/yuseok89.py new file mode 100644 index 0000000000..51b1b6c737 --- /dev/null +++ b/longest-consecutive-sequence/yuseok89.py @@ -0,0 +1,18 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + nums_unique = set(nums) + + ans = 0 + + for num in nums_unique: + if (num - 1) in nums_unique: + continue + + next = num + 1 + + while next in nums_unique: + next = next + 1 + + ans = max(ans, next - num) + + return ans From 4e4e41226157b830cd23f7acfae3c40f21d169f6 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 23 Jun 2026 22:56:20 +0900 Subject: [PATCH 05/26] house robber solution --- house-robber/yuseok89.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 house-robber/yuseok89.py diff --git a/house-robber/yuseok89.py b/house-robber/yuseok89.py new file mode 100644 index 0000000000..1fb92d3b85 --- /dev/null +++ b/house-robber/yuseok89.py @@ -0,0 +1,11 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + + two_before, one_before = 0, 0 + + for num in nums: + cur = max(two_before + num, one_before) + two_before = one_before + one_before = cur + + return max(one_before, two_before) From 32cafb9bd6b4b597fd598b7d1c8ee79a11adff79 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 23 Jun 2026 23:06:02 +0900 Subject: [PATCH 06/26] add newline --- contains-duplicate/yuseok89.py | 1 + house-robber/yuseok89.py | 1 + longest-consecutive-sequence/yuseok89.py | 1 + top-k-frequent-elements/yuseok89.py | 1 + two-sum/yuseok89.py | 1 + 5 files changed, 5 insertions(+) diff --git a/contains-duplicate/yuseok89.py b/contains-duplicate/yuseok89.py index 8648095834..4069db8cfd 100644 --- a/contains-duplicate/yuseok89.py +++ b/contains-duplicate/yuseok89.py @@ -9,3 +9,4 @@ def containsDuplicate(self, nums: List[int]) -> bool: dup_check.add(num) return False + diff --git a/house-robber/yuseok89.py b/house-robber/yuseok89.py index 1fb92d3b85..cfda251e07 100644 --- a/house-robber/yuseok89.py +++ b/house-robber/yuseok89.py @@ -9,3 +9,4 @@ def rob(self, nums: List[int]) -> int: one_before = cur return max(one_before, two_before) + diff --git a/longest-consecutive-sequence/yuseok89.py b/longest-consecutive-sequence/yuseok89.py index 51b1b6c737..9f1c9c8e1b 100644 --- a/longest-consecutive-sequence/yuseok89.py +++ b/longest-consecutive-sequence/yuseok89.py @@ -16,3 +16,4 @@ def longestConsecutive(self, nums: List[int]) -> int: ans = max(ans, next - num) return ans + diff --git a/top-k-frequent-elements/yuseok89.py b/top-k-frequent-elements/yuseok89.py index bfaa5de681..89f682014d 100644 --- a/top-k-frequent-elements/yuseok89.py +++ b/top-k-frequent-elements/yuseok89.py @@ -26,3 +26,4 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]: ret.append(num) return ret + diff --git a/two-sum/yuseok89.py b/two-sum/yuseok89.py index 2033711307..c4ab442451 100644 --- a/two-sum/yuseok89.py +++ b/two-sum/yuseok89.py @@ -12,3 +12,4 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: return [idx, idx_map[need]] return [] + From 49ecb593fae4f41ec5eaec4cd537a20976835602 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 25 Jun 2026 17:55:26 +0900 Subject: [PATCH 07/26] =?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 --- contains-duplicate/yuseok89.py | 1 + house-robber/yuseok89.py | 1 + longest-consecutive-sequence/yuseok89.py | 1 + top-k-frequent-elements/yuseok89.py | 1 + two-sum/yuseok89.py | 6 +++--- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/contains-duplicate/yuseok89.py b/contains-duplicate/yuseok89.py index 4069db8cfd..ec20f41283 100644 --- a/contains-duplicate/yuseok89.py +++ b/contains-duplicate/yuseok89.py @@ -1,3 +1,4 @@ +// TC: O(n), SC: O(n) class Solution: def containsDuplicate(self, nums: List[int]) -> bool: dup_check = set() diff --git a/house-robber/yuseok89.py b/house-robber/yuseok89.py index cfda251e07..f80ad1fd5d 100644 --- a/house-robber/yuseok89.py +++ b/house-robber/yuseok89.py @@ -1,3 +1,4 @@ +// TC: O(n), SC: O(1) class Solution: def rob(self, nums: List[int]) -> int: diff --git a/longest-consecutive-sequence/yuseok89.py b/longest-consecutive-sequence/yuseok89.py index 9f1c9c8e1b..6ced67e7f6 100644 --- a/longest-consecutive-sequence/yuseok89.py +++ b/longest-consecutive-sequence/yuseok89.py @@ -1,3 +1,4 @@ +// TC: O(n), SC: O(n) class Solution: def longestConsecutive(self, nums: List[int]) -> int: nums_unique = set(nums) diff --git a/top-k-frequent-elements/yuseok89.py b/top-k-frequent-elements/yuseok89.py index 89f682014d..735e8be199 100644 --- a/top-k-frequent-elements/yuseok89.py +++ b/top-k-frequent-elements/yuseok89.py @@ -1,3 +1,4 @@ +// TC: O(N + UlogK), SC: O(N) class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: diff --git a/two-sum/yuseok89.py b/two-sum/yuseok89.py index c4ab442451..25795b86c9 100644 --- a/two-sum/yuseok89.py +++ b/two-sum/yuseok89.py @@ -1,15 +1,15 @@ +// TC: O(N), SC: O(N) class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: idx_map = {} - for idx, num in enumerate(nums): - idx_map[num] = idx - for idx, num in enumerate(nums): need = target - num if need in idx_map and idx != idx_map[need]: return [idx, idx_map[need]] + idx_map[num] = idx + return [] From a6fcc338d45e7f75ade275a10811bf5e3d04faf2 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 25 Jun 2026 23:03:24 +0900 Subject: [PATCH 08/26] =?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 --- contains-duplicate/yuseok89.py | 3 ++- house-robber/yuseok89.py | 3 ++- longest-consecutive-sequence/yuseok89.py | 3 ++- top-k-frequent-elements/yuseok89.py | 3 ++- two-sum/yuseok89.py | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/contains-duplicate/yuseok89.py b/contains-duplicate/yuseok89.py index ec20f41283..6fa83a73ee 100644 --- a/contains-duplicate/yuseok89.py +++ b/contains-duplicate/yuseok89.py @@ -1,4 +1,5 @@ -// TC: O(n), SC: O(n) +// TC: O(n) +// SC: O(n) class Solution: def containsDuplicate(self, nums: List[int]) -> bool: dup_check = set() diff --git a/house-robber/yuseok89.py b/house-robber/yuseok89.py index f80ad1fd5d..46ef967c2c 100644 --- a/house-robber/yuseok89.py +++ b/house-robber/yuseok89.py @@ -1,4 +1,5 @@ -// TC: O(n), SC: O(1) +// TC: O(n) +// SC: O(1) class Solution: def rob(self, nums: List[int]) -> int: diff --git a/longest-consecutive-sequence/yuseok89.py b/longest-consecutive-sequence/yuseok89.py index 6ced67e7f6..224fd8b765 100644 --- a/longest-consecutive-sequence/yuseok89.py +++ b/longest-consecutive-sequence/yuseok89.py @@ -1,4 +1,5 @@ -// TC: O(n), SC: O(n) +// TC: O(n) +// SC: O(n) class Solution: def longestConsecutive(self, nums: List[int]) -> int: nums_unique = set(nums) diff --git a/top-k-frequent-elements/yuseok89.py b/top-k-frequent-elements/yuseok89.py index 735e8be199..2a3e09de76 100644 --- a/top-k-frequent-elements/yuseok89.py +++ b/top-k-frequent-elements/yuseok89.py @@ -1,4 +1,5 @@ -// TC: O(N + UlogK), SC: O(N) +// TC: O(NlogK) +// SC: O(N) class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: diff --git a/two-sum/yuseok89.py b/two-sum/yuseok89.py index 25795b86c9..b5465ca79c 100644 --- a/two-sum/yuseok89.py +++ b/two-sum/yuseok89.py @@ -1,4 +1,5 @@ -// TC: O(N), SC: O(N) +// TC: O(N) +// SC: O(N) class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: idx_map = {} From 38a1f6799faf6a7c2eb01cfd7dadc1e33ed207ff Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 25 Jun 2026 23:43:03 +0900 Subject: [PATCH 09/26] =?UTF-8?q?=EA=B0=9C=EC=84=A0=20-=20AI=20assist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- top-k-frequent-elements/yuseok89.py | 33 ++++++++++++----------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/top-k-frequent-elements/yuseok89.py b/top-k-frequent-elements/yuseok89.py index 2a3e09de76..ba1f1fd779 100644 --- a/top-k-frequent-elements/yuseok89.py +++ b/top-k-frequent-elements/yuseok89.py @@ -1,31 +1,26 @@ -// TC: O(NlogK) +// TC: O(N) // SC: O(N) class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: - import heapq + cnt = Counter(nums) # TC: O(n) + freq_map = defaultdict(list) + freq_max = 0 - heap = [] - cnt = {} + for num, freq in cnt.items(): + freq_map[freq].append(num) + freq_max = max(freq_max, freq) - for num in nums: - if num not in cnt: - cnt[num] = 0 - - cnt[num] = cnt[num] + 1 + ret = [] - for num in cnt.keys(): - if len(heap) < k: - heapq.heappush(heap, cnt[num]) - elif heap[0] < cnt[num]: - heapq.heappop(heap) - heapq.heappush(heap, cnt[num]) + for freq in range(freq_max, 0, -1): + if freq not in freq_map: + continue - ret = [] + ret.extend(freq_map[freq]) - for num in cnt.keys(): - if cnt[num] >= heap[0]: - ret.append(num) + if len(ret) >= k: + break return ret From 8bd5a3234eddb92d76d5b516e4cf7a1128fa8d80 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Mon, 29 Jun 2026 22:50:12 +0900 Subject: [PATCH 10/26] valid anagram solution --- valid-anagram/yuseok89.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 valid-anagram/yuseok89.py diff --git a/valid-anagram/yuseok89.py b/valid-anagram/yuseok89.py new file mode 100644 index 0000000000..b01f9d8a07 --- /dev/null +++ b/valid-anagram/yuseok89.py @@ -0,0 +1,13 @@ +## TC: O(N) +## SC: O(1) +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + + if len(s) != len(t): + return False + + cnt_s = Counter(s) + cnt_t = Counter(t) + + return cnt_s == cnt_t + From cd23e3477799470f65c2405657fa4799c74bb630 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Mon, 29 Jun 2026 23:25:19 +0900 Subject: [PATCH 11/26] climbing stairs solution --- climbing-stairs/yuseok89.py | 15 +++++++++++++++ valid-anagram/yuseok89.py | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 climbing-stairs/yuseok89.py diff --git a/climbing-stairs/yuseok89.py b/climbing-stairs/yuseok89.py new file mode 100644 index 0000000000..98908f9b6d --- /dev/null +++ b/climbing-stairs/yuseok89.py @@ -0,0 +1,15 @@ +# TC: O(N) +# SC: O(1) +class Solution: + def climbStairs(self, n: int) -> int: + + one_down = 1 + two_down = 0 + + for _ in range(1, n): + cur = two_down + one_down + two_down = one_down + one_down = cur + + return two_down + one_down + diff --git a/valid-anagram/yuseok89.py b/valid-anagram/yuseok89.py index b01f9d8a07..1d40aed598 100644 --- a/valid-anagram/yuseok89.py +++ b/valid-anagram/yuseok89.py @@ -1,5 +1,5 @@ -## TC: O(N) -## SC: O(1) +# TC: O(N) +# SC: O(K) class Solution: def isAnagram(self, s: str, t: str) -> bool: From 120df1f0479b013444edafaab50a80f096e9e5e5 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 1 Jul 2026 09:50:50 +0900 Subject: [PATCH 12/26] product of array except self solution --- product-of-array-except-self/yuseok89.py | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 product-of-array-except-self/yuseok89.py diff --git a/product-of-array-except-self/yuseok89.py b/product-of-array-except-self/yuseok89.py new file mode 100644 index 0000000000..7a4cd4bb3b --- /dev/null +++ b/product-of-array-except-self/yuseok89.py @@ -0,0 +1,25 @@ +// TC: O(N) +// SC: O(N) +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + + n = len(nums) + prefix_prod = [0] * n + suffix_prod = [0] * n + + prefix_prod[0] = nums[0] + suffix_prod[-1] = nums[-1] + + for idx in range(1, n): + prefix_prod[idx] = prefix_prod[idx - 1] * nums[idx] + suffix_prod[-idx - 1] = suffix_prod[-idx] * nums[-idx - 1] + + ret = [] + + ret.append(suffix_prod[1]) + for idx in range(1, n - 1): + ret.append(prefix_prod[idx - 1] * suffix_prod[idx + 1]) + ret.append(prefix_prod[n - 2]) + + return ret + From 1d4ff54af3cf097c58c1cff5b84bbf925b2ac5ea Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 1 Jul 2026 10:34:53 +0900 Subject: [PATCH 13/26] 3sum solution --- 3sum/yuseok89.py | 33 ++++++++++++++++++++++++ product-of-array-except-self/yuseok89.py | 4 +-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 3sum/yuseok89.py diff --git a/3sum/yuseok89.py b/3sum/yuseok89.py new file mode 100644 index 0000000000..52d477339f --- /dev/null +++ b/3sum/yuseok89.py @@ -0,0 +1,33 @@ +# TC: O(N^2) +# SC: O(N) +class Solution: + def threeSum(self, nums: list[int]) -> list[list[int]]: + + cnt_dict = Counter(nums) + nums_uniq = sorted(cnt_dict.keys()) + n = len(nums_uniq) + + ret = [] + + for num in cnt_dict.keys(): + if num == 0: + if cnt_dict[num] >= 3: + ret.append([0, 0, 0]) + elif cnt_dict[num] >= 2 and num * 2 * -1 in cnt_dict: + ret.append([num, num, num * 2 * -1]) + + for idx1, num1 in enumerate(nums_uniq): + if num1 > 0: + break + + for idx2 in range(idx1 + 1, n): + num2 = nums_uniq[idx2] + num3 = (num1 + num2) * -1 + + if num2 >= num3: + break + elif num3 in cnt_dict: + ret.append([num1, num2, num3]) + + return ret + diff --git a/product-of-array-except-self/yuseok89.py b/product-of-array-except-self/yuseok89.py index 7a4cd4bb3b..2acceaf3c5 100644 --- a/product-of-array-except-self/yuseok89.py +++ b/product-of-array-except-self/yuseok89.py @@ -1,5 +1,5 @@ -// TC: O(N) -// SC: O(N) +# TC: O(N) +# SC: O(N) class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: From 23142a79ef3d5f6ec82389e38d51ded81d205130 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 1 Jul 2026 10:52:46 +0900 Subject: [PATCH 14/26] validate binary search tree solution --- validate-binary-search-tree/yuseok89.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 validate-binary-search-tree/yuseok89.py diff --git a/validate-binary-search-tree/yuseok89.py b/validate-binary-search-tree/yuseok89.py new file mode 100644 index 0000000000..9f1601f00b --- /dev/null +++ b/validate-binary-search-tree/yuseok89.py @@ -0,0 +1,23 @@ +# TC: O(N) +# SC: O(1) +# Definition for a binary tree node. +# class TreeNode: +# def __init__(self, val=0, left=None, right=None): +# self.val = val +# self.left = left +# self.right = right +class Solution: + + def isValid(self, left_bound, right_bound, root): + if root is None: + return True + if left_bound is not None and left_bound >= root.val: + return False + if right_bound is not None and right_bound <= root.val: + return False + + return self.isValid(left_bound, root.val, root.left) and self.isValid(root.val, right_bound, root.right) + + def isValidBST(self, root: Optional[TreeNode]) -> bool: + return self.isValid(None, root.val, root.left) and self.isValid(root.val, None, root.right) + From 0cb14caa06d27da29b7434e29ab8e9434db7c2c3 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 1 Jul 2026 11:29:40 +0900 Subject: [PATCH 15/26] =?UTF-8?q?=EA=B3=B5=EA=B0=84=EB=B3=B5=EC=9E=A1?= =?UTF-8?q?=EB=8F=84=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- validate-binary-search-tree/yuseok89.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/validate-binary-search-tree/yuseok89.py b/validate-binary-search-tree/yuseok89.py index 9f1601f00b..0e9cc2015d 100644 --- a/validate-binary-search-tree/yuseok89.py +++ b/validate-binary-search-tree/yuseok89.py @@ -1,5 +1,5 @@ # TC: O(N) -# SC: O(1) +# SC: O(H) # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): From 9465142cf0b49c73828130b336a370cd153879db Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 1 Jul 2026 13:24:59 +0900 Subject: [PATCH 16/26] =?UTF-8?q?=EA=B3=B5=EA=B0=84=EB=B3=B5=EC=9E=A1?= =?UTF-8?q?=EB=8F=84=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-anagram/yuseok89.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/valid-anagram/yuseok89.py b/valid-anagram/yuseok89.py index 1d40aed598..f8793092e7 100644 --- a/valid-anagram/yuseok89.py +++ b/valid-anagram/yuseok89.py @@ -1,5 +1,5 @@ # TC: O(N) -# SC: O(K) +# SC: O(1) class Solution: def isAnagram(self, s: str, t: str) -> bool: From 4b09054de351728b6558c4fc8e2d63009307293e Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 7 Jul 2026 23:16:06 +0900 Subject: [PATCH 17/26] validate palindrome solution --- valid-palindrome/yuseok89.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 valid-palindrome/yuseok89.py diff --git a/valid-palindrome/yuseok89.py b/valid-palindrome/yuseok89.py new file mode 100644 index 0000000000..803ee69342 --- /dev/null +++ b/valid-palindrome/yuseok89.py @@ -0,0 +1,17 @@ +# TC: O(N) +# SC: O(1) +class Solution: + def isPalindrome(self, s: str) -> bool: + + import re + + s = re.sub(r'[^a-zA-Z0-9]', '', s.lower()) + + n = len(s) + + for idx in range(0, n // 2): + if s[idx] != s[n - idx - 1]: + return False + + return True + From da3aad9b94b888724f7c02b4fb7a49ac75e78896 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 7 Jul 2026 23:17:03 +0900 Subject: [PATCH 18/26] number of 1 bits solution --- number-of-1-bits/yuseok89.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 number-of-1-bits/yuseok89.py diff --git a/number-of-1-bits/yuseok89.py b/number-of-1-bits/yuseok89.py new file mode 100644 index 0000000000..a70faf428e --- /dev/null +++ b/number-of-1-bits/yuseok89.py @@ -0,0 +1,13 @@ +# TC: O(logN) +# SC: O(1) +class Solution: + def hammingWeight(self, n: int) -> int: + + cnt = 0 + + while n > 0: + cnt = cnt + (n % 2) + n //= 2 + + return cnt + From 5c4d5fb201a71ff3f487ff62656673b9c7711847 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 7 Jul 2026 23:20:41 +0900 Subject: [PATCH 19/26] combination sum solution --- combination-sum/yuseok89.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 combination-sum/yuseok89.py diff --git a/combination-sum/yuseok89.py b/combination-sum/yuseok89.py new file mode 100644 index 0000000000..b6c087d60c --- /dev/null +++ b/combination-sum/yuseok89.py @@ -0,0 +1,27 @@ +# TC: O(NlogN) +# SC: O(logN) +class Solution: + + def rec(self, cur, candi, combi, sum, target, ans): + + if sum == target: + ans.append(combi) + + return + + for idx in range(cur, len(candi)): + + multi = 1 + + while sum + multi * candi[idx] <= target: + self.rec(idx + 1, candi, combi + [candi[idx]] * multi, sum + multi * candi[idx], target, ans) + multi += 1 + + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + + ans = [] + + self.rec(0, candidates, [], 0, target, ans) + + return ans + From 03f3f1a86cbba6092791e8c70b7ddab3a76b00f1 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 7 Jul 2026 23:21:51 +0900 Subject: [PATCH 20/26] decode ways solution --- decode-ways/yuseok89.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 decode-ways/yuseok89.py diff --git a/decode-ways/yuseok89.py b/decode-ways/yuseok89.py new file mode 100644 index 0000000000..da6c0da328 --- /dev/null +++ b/decode-ways/yuseok89.py @@ -0,0 +1,29 @@ +# TC: O(N) +# SC: O(N) +class Solution: + + memo = [] + + def rec(self, idx, s, n): + if self.memo[idx] == -1: + + cnt = 0 + + if int(s[idx]) != 0: + cnt += self.rec(idx + 1, s, n) + + if idx + 1 < n: + if int(s[idx]) != 0 and int(s[idx]) * 10 + int(s[idx + 1]) <= 26: + cnt += self.rec(idx + 2, s, n) + + self.memo[idx] = cnt + + return self.memo[idx] + + def numDecodings(self, s: str) -> int: + + self.memo = [-1] * (len(s) + 1) + self.memo[len(s)] = 1 + + return self.rec(0, s, len(s)) + From d8d5ea42a16b07442940b3c273c71cc8f1ad5312 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 7 Jul 2026 23:22:50 +0900 Subject: [PATCH 21/26] maximum subarray solution --- maximum-subarray/yuseok89.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 maximum-subarray/yuseok89.py diff --git a/maximum-subarray/yuseok89.py b/maximum-subarray/yuseok89.py new file mode 100644 index 0000000000..e56c8f9e4f --- /dev/null +++ b/maximum-subarray/yuseok89.py @@ -0,0 +1,17 @@ +# TC: O(N) +# SC: O(1) +class Solution: + def maxSubArray(self, nums: List[int]) -> int: + sum = nums[0] if nums[0] < 0 else 0 + ans = sum + + for num in nums: + if num > sum + num: + sum = num + else: + sum += num + + ans = max(ans, sum) + + return ans + From 1f003e2d4777b9cfb3fa4c60395b2520fd27643f Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Wed, 8 Jul 2026 00:35:01 +0900 Subject: [PATCH 22/26] =?UTF-8?q?=EB=B3=B5=EC=9E=A1=EB=8F=84=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- combination-sum/yuseok89.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/combination-sum/yuseok89.py b/combination-sum/yuseok89.py index b6c087d60c..59f4bf2eed 100644 --- a/combination-sum/yuseok89.py +++ b/combination-sum/yuseok89.py @@ -1,5 +1,5 @@ -# TC: O(NlogN) -# SC: O(logN) +# TC: O(K*N!) +# SC: O(K) class Solution: def rec(self, cur, candi, combi, sum, target, ans): From a022d1040a0a1926e24c26c3ceb3de35b8a7a721 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 9 Jul 2026 20:07:01 +0900 Subject: [PATCH 23/26] =?UTF-8?q?=EC=9E=AC=EA=B7=80=20=EB=A1=9C=EC=A7=81?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- combination-sum/yuseok89.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/combination-sum/yuseok89.py b/combination-sum/yuseok89.py index 59f4bf2eed..6003c0fc24 100644 --- a/combination-sum/yuseok89.py +++ b/combination-sum/yuseok89.py @@ -1,27 +1,28 @@ -# TC: O(K*N!) -# SC: O(K) +# TC: O(N^T) +# SC: O(T) class Solution: - def rec(self, cur, candi, combi, sum, target, ans): + def rec(self, cur_idx, target, candi, cur_combi, ans): - if sum == target: - ans.append(combi) + if target == 0: + ans.append(cur_combi.copy()) + if cur_idx == len(candi): return - for idx in range(cur, len(candi)): + for idx in range(cur_idx, len(candi)): + if target < candi[idx]: + continue - multi = 1 - - while sum + multi * candi[idx] <= target: - self.rec(idx + 1, candi, combi + [candi[idx]] * multi, sum + multi * candi[idx], target, ans) - multi += 1 + cur_combi.append(candi[idx]) + self.rec(idx, target - candi[idx], candi, cur_combi, ans) + cur_combi.pop() def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: ans = [] - self.rec(0, candidates, [], 0, target, ans) + self.rec(0, target, candidates, [], ans) return ans From b8248c42f5d47b02e22f8a884eca32822396fecb Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 9 Jul 2026 20:19:29 +0900 Subject: [PATCH 24/26] =?UTF-8?q?maximum=20subarray=20=ED=92=80=EC=9D=B4?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maximum-subarray/yuseok89.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/maximum-subarray/yuseok89.py b/maximum-subarray/yuseok89.py index e56c8f9e4f..b8c10491dd 100644 --- a/maximum-subarray/yuseok89.py +++ b/maximum-subarray/yuseok89.py @@ -6,12 +6,19 @@ def maxSubArray(self, nums: List[int]) -> int: ans = sum for num in nums: - if num > sum + num: - sum = num - else: - sum += num - + sum = max(num, sum + num) ans = max(ans, sum) return ans +# class Solution: +# def maxSubArray(self, nums: List[int]) -> int: +# sum = nums[0] +# ans = sum + +# for idx in range(1, len(nums)): +# sum = max(nums[idx], sum + nums[idx]) +# ans = max(ans, sum) + +# return ans + From 51c1012373a7f2a0eea69b9fd14b6954c87b7a44 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 9 Jul 2026 20:29:11 +0900 Subject: [PATCH 25/26] =?UTF-8?q?valid=20palindrome=20=ED=92=80=EC=9D=B4?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-palindrome/yuseok89.py | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/valid-palindrome/yuseok89.py b/valid-palindrome/yuseok89.py index 803ee69342..4af870bc87 100644 --- a/valid-palindrome/yuseok89.py +++ b/valid-palindrome/yuseok89.py @@ -1,17 +1,43 @@ # TC: O(N) # SC: O(1) class Solution: + + def is_alphanum(self, c): + return 'a' <= c <= 'z' or '0' <= c <= '9' + def isPalindrome(self, s: str) -> bool: - import re + left = 0 + right = len(s) - 1 - s = re.sub(r'[^a-zA-Z0-9]', '', s.lower()) + s = s.lower() - n = len(s) + while(left < right): + while left < len(s) and not self.is_alphanum(s[left]): + left += 1 + while right >= 0 and not self.is_alphanum(s[right]): + right -= 1 - for idx in range(0, n // 2): - if s[idx] != s[n - idx - 1]: + if left < right and s[left] != s[right]: return False + left += 1 + right -= 1 + return True +# class Solution: +# def isPalindrome(self, s: str) -> bool: +# +# import re +# +# s = re.sub(r'[^a-zA-Z0-9]', '', s.lower()) +# +# n = len(s) +# +# for idx in range(0, n // 2): +# if s[idx] != s[n - idx - 1]: +# return False +# +# return True + From 65431c08ae2c95174a9380505e43e75ddf08b4e4 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Thu, 9 Jul 2026 20:38:37 +0900 Subject: [PATCH 26/26] =?UTF-8?q?maximum=20subarray=20=ED=92=80=EC=9D=B4?= =?UTF-8?q?=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- maximum-subarray/yuseok89.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maximum-subarray/yuseok89.py b/maximum-subarray/yuseok89.py index b8c10491dd..0056aae9be 100644 --- a/maximum-subarray/yuseok89.py +++ b/maximum-subarray/yuseok89.py @@ -2,10 +2,10 @@ # SC: O(1) class Solution: def maxSubArray(self, nums: List[int]) -> int: - sum = nums[0] if nums[0] < 0 else 0 + sum = nums[0] ans = sum - for num in nums: + for num in nums[1:]: sum = max(num, sum + num) ans = max(ans, sum) @@ -13,11 +13,11 @@ def maxSubArray(self, nums: List[int]) -> int: # class Solution: # def maxSubArray(self, nums: List[int]) -> int: -# sum = nums[0] +# sum = nums[0] if nums[0] < 0 else 0 # ans = sum -# for idx in range(1, len(nums)): -# sum = max(nums[idx], sum + nums[idx]) +# for num in nums: +# sum = max(num, sum + num) # ans = max(ans, sum) # return ans