From dc34f9326464419aa4f66eccfca93dff283d2d31 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 24 Jul 2026 23:36:28 +0900 Subject: [PATCH 1/7] best time to buy and sell stock solution --- best-time-to-buy-and-sell-stock/yuseok89.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/yuseok89.py diff --git a/best-time-to-buy-and-sell-stock/yuseok89.py b/best-time-to-buy-and-sell-stock/yuseok89.py new file mode 100644 index 0000000000..dcd26582c9 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/yuseok89.py @@ -0,0 +1,13 @@ +# TC: O(N) +# SC: O(1) +class Solution: + def maxProfit(self, prices: List[int]) -> int: + min_until_now = prices[0] + max_profit = 0 + + for price in prices: + max_profit = max(max_profit, price - min_until_now) + min_until_now = min(min_until_now, price) + + return max_profit + From 96a81aac5d453a0c9f016888c5e871cf71230986 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 24 Jul 2026 23:36:50 +0900 Subject: [PATCH 2/7] group anagrams solution --- group-anagrams/yuseok89.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 group-anagrams/yuseok89.py diff --git a/group-anagrams/yuseok89.py b/group-anagrams/yuseok89.py new file mode 100644 index 0000000000..bffab56efe --- /dev/null +++ b/group-anagrams/yuseok89.py @@ -0,0 +1,12 @@ +# TC: O(N * LlogL) +# SC: O(N * L) +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + + ans = defaultdict(list) + + for s in strs: + ans[''.join(sorted(s))].append(s) + + return list(ans.values()) + From 04a8b21265244f7706045f84a570d10471a0953a Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 24 Jul 2026 23:37:22 +0900 Subject: [PATCH 3/7] implement trie prefix tree solution --- implement-trie-prefix-tree/yuseok89.py | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 implement-trie-prefix-tree/yuseok89.py diff --git a/implement-trie-prefix-tree/yuseok89.py b/implement-trie-prefix-tree/yuseok89.py new file mode 100644 index 0000000000..de928a9957 --- /dev/null +++ b/implement-trie-prefix-tree/yuseok89.py @@ -0,0 +1,52 @@ +# TC: O(L) +# SC: O(L * N) +class TrieNode: + def __init__(self): + self.next = {} + self.is_end = False + +class Trie: + + def __init__(self): + self.root = TrieNode() + + def insert(self, word: str) -> None: + cur = self.root + + for c in word: + if c not in cur.next: + cur.next[c] = TrieNode() + + cur = cur.next[c] + + cur.is_end = True + + def search(self, word: str) -> bool: + cur = self.root + + for c in word: + if c not in cur.next: + return False + + cur = cur.next[c] + + return cur.is_end + + def startsWith(self, prefix: str) -> bool: + cur = self.root + + for c in prefix: + if c not in cur.next: + return False + + cur = cur.next[c] + + return True + + +# Your Trie object will be instantiated and called as such: +# obj = Trie() +# obj.insert(word) +# param_2 = obj.search(word) +# param_3 = obj.startsWith(prefix) + From b8d817a4a83600ea261d46d378fbc998849afa58 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 24 Jul 2026 23:38:01 +0900 Subject: [PATCH 4/7] word break solution --- word-break/yuseok89.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 word-break/yuseok89.py diff --git a/word-break/yuseok89.py b/word-break/yuseok89.py new file mode 100644 index 0000000000..00175abffc --- /dev/null +++ b/word-break/yuseok89.py @@ -0,0 +1,38 @@ +#TC: O() +#SC: O() +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + + word_set = set() + + max_len = 0 + min_len = 300 + + for word in wordDict: + word_set.add(word) + max_len = max(max_len, len(word)) + min_len = min(min_len, len(word)) + + v = set() + + def rec(cur): + if cur in v: + return False + + v.add(cur) + + if len(cur) == 0: + return True + + for l in range(min_len, max_len + 1): + if len(cur) < l: + return False + + if cur[0:l] in word_set: + if rec(cur[l:]): + return True + + return False + + return rec(s) + From 82f26dc52633bddfd5efaa55a3469341fdd453ba Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 24 Jul 2026 23:44:17 +0900 Subject: [PATCH 5/7] =?UTF-8?q?min,=20max=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- best-time-to-buy-and-sell-stock/yuseok89.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/best-time-to-buy-and-sell-stock/yuseok89.py b/best-time-to-buy-and-sell-stock/yuseok89.py index dcd26582c9..41e58cb30e 100644 --- a/best-time-to-buy-and-sell-stock/yuseok89.py +++ b/best-time-to-buy-and-sell-stock/yuseok89.py @@ -6,8 +6,13 @@ def maxProfit(self, prices: List[int]) -> int: max_profit = 0 for price in prices: - max_profit = max(max_profit, price - min_until_now) - min_until_now = min(min_until_now, price) + profit = price - min_until_now + + if profit > max_profit: + max_profit = profit + + if price < min_until_now: + min_until_now = price return max_profit From ac3a659a0e5357cba677e4b7df46afb187465922 Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 24 Jul 2026 23:47:25 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=EA=B3=B5=EB=9E=80=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- word-break/yuseok89.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/word-break/yuseok89.py b/word-break/yuseok89.py index 00175abffc..611a1ed358 100644 --- a/word-break/yuseok89.py +++ b/word-break/yuseok89.py @@ -1,5 +1,3 @@ -#TC: O() -#SC: O() class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: From b5f763d3b9528c2982c532055e87a6c015b4a68b Mon Sep 17 00:00:00 2001 From: Yuseok Jo Date: Fri, 24 Jul 2026 23:56:50 +0900 Subject: [PATCH 7/7] =?UTF-8?q?word=20break=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- word-break/yuseok89.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/word-break/yuseok89.py b/word-break/yuseok89.py index 611a1ed358..e774129444 100644 --- a/word-break/yuseok89.py +++ b/word-break/yuseok89.py @@ -2,27 +2,23 @@ class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: word_set = set() - - max_len = 0 - min_len = 300 + word_lens = set() for word in wordDict: word_set.add(word) - max_len = max(max_len, len(word)) - min_len = min(min_len, len(word)) + word_lens.add(len(word)) - v = set() + word_lens = sorted(word_lens) + visited = set() def rec(cur): - if cur in v: + if cur in visited: return False - v.add(cur) - if len(cur) == 0: return True - for l in range(min_len, max_len + 1): + for l in word_lens: if len(cur) < l: return False @@ -30,6 +26,8 @@ def rec(cur): if rec(cur[l:]): return True + visited.add(cur) + return False return rec(s)