From 3f75a5bc2a220b797613a8e758686f55bc19c039 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Tue, 9 Dec 2025 10:22:14 -0500 Subject: [PATCH 1/7] 121. Best Time to Buy and Sell Stock Solution --- best-time-to-buy-and-sell-stock/doh6077.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/doh6077.py diff --git a/best-time-to-buy-and-sell-stock/doh6077.py b/best-time-to-buy-and-sell-stock/doh6077.py new file mode 100644 index 0000000000..42967c5e09 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/doh6077.py @@ -0,0 +1,18 @@ + +# 121. Best Time to Buy and Sell Stock +# O(n) - Two Pointers +class Solution: + def maxProfit(self, prices: list[int]) -> int: + left = 0 + right = 1 + profit = 0 + max_profit = 0 + + while right < len(prices): + if prices[right] > prices[left]: + profit = prices[right] - prices[left] + max_profit = max(profit, max_profit) + else: + left = right + right += 1 + return max_profit From 82c3b57e70a9a986be71a9a00a9af7503a394314 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 12 Dec 2025 14:02:18 -0500 Subject: [PATCH 2/7] 49. Group Anagrams Solution --- group-anagrams/doh6077.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 group-anagrams/doh6077.py diff --git a/group-anagrams/doh6077.py b/group-anagrams/doh6077.py new file mode 100644 index 0000000000..b0dcbd6237 --- /dev/null +++ b/group-anagrams/doh6077.py @@ -0,0 +1,18 @@ +from collections import defaultdict +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + # hashmap + # calculate frequency + # 26 alphabet characters + anagrams_dict = defaultdict(list) + for s in strs: + count = [0] * 26 + for c in s: + count[ord(c) - ord('a')] += 1 + + key = tuple(count) + anagrams_dict[key].append(s) + + return list(anagrams_dict.values()) + + \ No newline at end of file From 386746fea8206da15c750c5b73f9e1d4b40fb9dd Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 12 Dec 2025 14:05:24 -0500 Subject: [PATCH 3/7] =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group-anagrams/doh6077.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/group-anagrams/doh6077.py b/group-anagrams/doh6077.py index b0dcbd6237..3bce15017c 100644 --- a/group-anagrams/doh6077.py +++ b/group-anagrams/doh6077.py @@ -14,5 +14,4 @@ def groupAnagrams(self, strs: List[str]) -> List[List[str]]: anagrams_dict[key].append(s) return list(anagrams_dict.values()) - - \ No newline at end of file + \ No newline at end of file From cea3eef0651a7448fd6468d877947c4bb41a01cc Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 12 Dec 2025 14:07:19 -0500 Subject: [PATCH 4/7] . --- group-anagrams/doh6077.py | 1 - 1 file changed, 1 deletion(-) diff --git a/group-anagrams/doh6077.py b/group-anagrams/doh6077.py index 3bce15017c..00db068520 100644 --- a/group-anagrams/doh6077.py +++ b/group-anagrams/doh6077.py @@ -14,4 +14,3 @@ def groupAnagrams(self, strs: List[str]) -> List[List[str]]: anagrams_dict[key].append(s) return list(anagrams_dict.values()) - \ No newline at end of file From 90db269eedc16addba6760f48a0593b762569c21 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 12 Dec 2025 15:43:37 -0500 Subject: [PATCH 5/7] 139. Word Break Solution --- word-break/doh6077.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 word-break/doh6077.py diff --git a/word-break/doh6077.py b/word-break/doh6077.py new file mode 100644 index 0000000000..fc20c0c036 --- /dev/null +++ b/word-break/doh6077.py @@ -0,0 +1,12 @@ +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + dp = [True] + [False] * len(s) + + for i in range(1, len(s) + 1): + for w in wordDict: + start = i - len(w) + if start >= 0 and dp[start] and s[start:i] == w: + dp[i] = True + break + + return dp[-1] From bc00ba9d8cee215b4b89d9504eaece0a65e772af Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 12 Dec 2025 15:58:18 -0500 Subject: [PATCH 6/7] 208. Implement Trie (Prefix Tree) Solution --- .../doh6077.py | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 design-add-and-search-words-data-structure/doh6077.py diff --git a/design-add-and-search-words-data-structure/doh6077.py b/design-add-and-search-words-data-structure/doh6077.py new file mode 100644 index 0000000000..43db9fed53 --- /dev/null +++ b/design-add-and-search-words-data-structure/doh6077.py @@ -0,0 +1,32 @@ + +# 208. Implement Trie (Prefix Tree) +class Trie: + + def __init__(self): + self.list = [] + + + def insert(self, word: str) -> None: + self.list.append(word) + + + def search(self, word: str) -> bool: + if word in self.list: + return True + else: + return False + + + def startsWith(self, prefix: str) -> bool: + for i, value in enumerate(self.list): + if value.startswith(prefix): + return True + return False + + + +# 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 4970077f6e9485dccb3893463dec2f3e1f5a8af5 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 12 Dec 2025 16:27:16 -0500 Subject: [PATCH 7/7] 271. Encode and Decode Strings Solution --- encode-and-decode-strings/doh6077.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 encode-and-decode-strings/doh6077.py diff --git a/encode-and-decode-strings/doh6077.py b/encode-and-decode-strings/doh6077.py new file mode 100644 index 0000000000..ef935478f8 --- /dev/null +++ b/encode-and-decode-strings/doh6077.py @@ -0,0 +1,26 @@ + + +# 271. Encode and Decode Strings + +# integer represents the following word's length +# read until we reach to delimiter + +class Solution: + def encode(self, strs): + res = "" + for s in strs: + res += str(len(s)) + "#" + s + return res + + def decode(self, str): + res, i = [], 0 + + while i < len(str): + j = i + while str[j] != "#": + j += 1 + length = int(str[i:j]) + res.append(str[j + 1 : j + 1 + length]) + i = j + 1 + length + + return res