From 4836151a04615e19e30bc88bca1deb359467b662 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Tue, 23 Jun 2026 22:50:15 +0900 Subject: [PATCH 01/16] 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/16] 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/16] 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/16] 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/16] 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/16] 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/16] =?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/16] =?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/16] =?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/16] 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/16] 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/16] 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/16] 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/16] 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/16] =?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/16] =?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: