From 130419a80e37a57cbc73771dc7a64408a89a43cc Mon Sep 17 00:00:00 2001 From: Daiyong Kim Date: Sun, 7 Dec 2025 10:14:59 -0800 Subject: [PATCH 1/6] adding best time to buy and sell stock --- best-time-to-buy-and-sell-stock/daiyongg-kim.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 best-time-to-buy-and-sell-stock/daiyongg-kim.py diff --git a/best-time-to-buy-and-sell-stock/daiyongg-kim.py b/best-time-to-buy-and-sell-stock/daiyongg-kim.py new file mode 100644 index 000000000..e69de29bb From 758a3547bd212e14860812fc20c34376ea675fea Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Mon, 8 Dec 2025 08:13:51 -0800 Subject: [PATCH 2/6] update best time to buy and sell stock --- best-time-to-buy-and-sell-stock/daiyongg-kim.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/best-time-to-buy-and-sell-stock/daiyongg-kim.py b/best-time-to-buy-and-sell-stock/daiyongg-kim.py index e69de29bb..c90793681 100644 --- a/best-time-to-buy-and-sell-stock/daiyongg-kim.py +++ b/best-time-to-buy-and-sell-stock/daiyongg-kim.py @@ -0,0 +1,12 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + min_price = prices[0] + max_profit = 0 + + for price in prices[1:]: + if price < min_price: + min_price = price + elif price - min_price > max_profit: + max_profit = price - min_price + + return max_profit From 9b859d078b8dcad4650d448b2540e955fc995cfe Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:47:53 -0800 Subject: [PATCH 3/6] update 2 problems --- encode-and-decode-strings/daiyongg-kim.py | 40 +++++++++++++++++++++++ group-anagrams/daiyongg-kim.py | 10 ++++++ word-break/daiyongg-kim.py | 14 ++++++++ 3 files changed, 64 insertions(+) create mode 100644 encode-and-decode-strings/daiyongg-kim.py create mode 100644 group-anagrams/daiyongg-kim.py create mode 100644 word-break/daiyongg-kim.py diff --git a/encode-and-decode-strings/daiyongg-kim.py b/encode-and-decode-strings/daiyongg-kim.py new file mode 100644 index 000000000..b7615f0d8 --- /dev/null +++ b/encode-and-decode-strings/daiyongg-kim.py @@ -0,0 +1,40 @@ +class Solution: + """ + @param: strs: a list of strings + @return: encodes a list of strings to a single string. + """ + def encode(self, strs): + # write your code here + result = "" + for word in strs: + word_size = len(word) + result += str(word_size) + "#" + word + + return result + # input ["lint","code","love","you"] + # output "4#lint4#code4#love3#you" + + """ + @param: str: A string + @return: decodes a single string to a list of strings + """ + def decode(self, str): + # write your code here + result = [] + i = 0 + while i < len(str): + j = i + while str[j] != "#": #find the position of '#' + j += 1 + + my_number = int(str[i:j]) + + start = j + 1 # add 1 to skip '#' + end = j + 1 + my_number + + result.append(str[start:end]) + i = end + + return result + # input "4#lint4#code4#love3#you" + # output ["lint","code","love","you"] diff --git a/group-anagrams/daiyongg-kim.py b/group-anagrams/daiyongg-kim.py new file mode 100644 index 000000000..b4509e63c --- /dev/null +++ b/group-anagrams/daiyongg-kim.py @@ -0,0 +1,10 @@ +class Solution: + def groupAnagrams(self, strs: List[str]) -> List[List[str]]: + group_anagram = defaultdict(list) + # 초기화: 키가 없으면 자동으로 list() 즉, []를 실행해서 값을 만듦 + + for word in strs: + sorted_word = ''.join(sorted(word)) + group_anagram[sorted_word].append(word) + + return list(group_anagram.values()) diff --git a/word-break/daiyongg-kim.py b/word-break/daiyongg-kim.py new file mode 100644 index 000000000..5a26d48a0 --- /dev/null +++ b/word-break/daiyongg-kim.py @@ -0,0 +1,14 @@ + + + +""" Failed Attempt + class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + + for word in wordDict: + if word in s: + s = s.replace(word, '') + else: + return False + return len(s) == 0 +""" \ No newline at end of file From 4d13e2af0d9f5161dd5d91f1b51bef7b0a9da7fa Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Mon, 8 Dec 2025 13:50:15 -0800 Subject: [PATCH 4/6] resolve line issue --- word-break/daiyongg-kim.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/word-break/daiyongg-kim.py b/word-break/daiyongg-kim.py index 5a26d48a0..25e78988a 100644 --- a/word-break/daiyongg-kim.py +++ b/word-break/daiyongg-kim.py @@ -1,6 +1,3 @@ - - - """ Failed Attempt class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: @@ -11,4 +8,6 @@ def wordBreak(self, s: str, wordDict: List[str]) -> bool: else: return False return len(s) == 0 -""" \ No newline at end of file +""" +class Solution: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: From 70de40125c33dd1197094355c443f904934ee01f Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Fri, 12 Dec 2025 21:15:06 -0800 Subject: [PATCH 5/6] adding word break --- word-break/daiyongg-kim.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/word-break/daiyongg-kim.py b/word-break/daiyongg-kim.py index 25e78988a..be2b9d041 100644 --- a/word-break/daiyongg-kim.py +++ b/word-break/daiyongg-kim.py @@ -1,3 +1,4 @@ + """ Failed Attempt class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: @@ -10,4 +11,15 @@ def wordBreak(self, s: str, wordDict: List[str]) -> bool: return len(s) == 0 """ class Solution: - def wordBreak(self, s: str, wordDict: List[str]) -> bool: + def wordBreak(self, s: str, wordDict: List[str]) -> bool: + word_set = set(wordDict) + + dp = [False] * (len(s) + 1) + dp[0] = True + + for i in range(1, len(s) + 1): + for j in range(i): + if dp[j] and s[j:i] in word_set: + dp[i] = True + break + return dp[len(s)] From 1c3a16ba09048f24e7de3438d07a88aeab2b3243 Mon Sep 17 00:00:00 2001 From: daiyongg-kim <134879427+daiyongg-kim@users.noreply.github.com> Date: Fri, 12 Dec 2025 22:23:51 -0800 Subject: [PATCH 6/6] adding implement trie prefix tree --- implement-trie-prefix-tree/daiyongg-kim.py | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 implement-trie-prefix-tree/daiyongg-kim.py diff --git a/implement-trie-prefix-tree/daiyongg-kim.py b/implement-trie-prefix-tree/daiyongg-kim.py new file mode 100644 index 000000000..af236c556 --- /dev/null +++ b/implement-trie-prefix-tree/daiyongg-kim.py @@ -0,0 +1,42 @@ +class Trie: + + def __init__(self): + self.children = {} + self.is_end = False + + def insert(self, word: str) -> None: + node = self + + for c in word: + if c not in node.children: + node.children[c] = Trie() + node = node.children[c] + + node.is_end = True + + + def search(self, word: str) -> bool: + node = self + + for c in word: + if c not in node.children: + return False + node = node.children[c] + + return node.is_end + + def startsWith(self, prefix: str) -> bool: + node = self + for c in prefix: + if c not in node.children: + return False + node = node.children[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)