From 09b4f02eadfffe2e4b50929271fabb9542c94ed4 Mon Sep 17 00:00:00 2001 From: changhyumm Date: Thu, 18 Dec 2025 23:33:05 +0900 Subject: [PATCH 1/6] valid parentheses --- container-with-most-water/changhyumm.py | 0 valid-parentheses/changhyumm.py | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 container-with-most-water/changhyumm.py create mode 100644 valid-parentheses/changhyumm.py diff --git a/container-with-most-water/changhyumm.py b/container-with-most-water/changhyumm.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/valid-parentheses/changhyumm.py b/valid-parentheses/changhyumm.py new file mode 100644 index 0000000000..dff39f8548 --- /dev/null +++ b/valid-parentheses/changhyumm.py @@ -0,0 +1,20 @@ +class Solution: + def isValid(self, s: str) -> bool: + brackets = {"(": ")", "{": "}", "[": "]"} + stack = [] + # 괄호의 특성상 stack 자료구조 활용 + # 시간 복잡도 O(n) + # 공간 복잡도 O(n) + for string in s: + if string not in brackets: + if len(stack) == 0: + return False + else: + target = stack.pop() + if string != target: + return False + else: + stack.append(brackets[string]) + if stack: + return False + return True From e33db1cd7969e809c4af0bf21c712463f4af8796 Mon Sep 17 00:00:00 2001 From: changhyumm Date: Thu, 18 Dec 2025 23:33:34 +0900 Subject: [PATCH 2/6] container with most water --- container-with-most-water/changhyumm.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/container-with-most-water/changhyumm.py b/container-with-most-water/changhyumm.py index e69de29bb2..99629993e2 100644 --- a/container-with-most-water/changhyumm.py +++ b/container-with-most-water/changhyumm.py @@ -0,0 +1,23 @@ +class Solution: + def maxArea(self, height: List[int]) -> int: + # 시간복잡도 O(n2)으로 타임아웃 + # max_amount = 0 + # for i in range(len(height) - 1): + # for j in range(i + 1, len(height)): + # amount = (j-i) * min(height[i], height[j]) + # max_amount = max(amount, max_amount) + # return max_amount + + # 투포인터 활용 + # 시간복잡도 O(n) + max_amount = 0 + left = 0 + right = len(height) - 1 + while left < right: + amount = (right - left) * min(height[left], height[right]) + max_amount = max(amount, max_amount) + if height[left] < height[right]: + left += 1 + else: + right -= 1 + return max_amount From 7cb90cc20c2d4e149fd8723fd6f0ff6f6c52afe4 Mon Sep 17 00:00:00 2001 From: changhyumm Date: Thu, 18 Dec 2025 23:49:23 +0900 Subject: [PATCH 3/6] week5 - 1 --- best-time-to-buy-and-sell-stock/changhyumm.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 best-time-to-buy-and-sell-stock/changhyumm.py diff --git a/best-time-to-buy-and-sell-stock/changhyumm.py b/best-time-to-buy-and-sell-stock/changhyumm.py new file mode 100644 index 0000000000..9a824aea99 --- /dev/null +++ b/best-time-to-buy-and-sell-stock/changhyumm.py @@ -0,0 +1,9 @@ +class Solution: + def maxProfit(self, prices: List[int]) -> int: + min_price = prices[0] + max_profit = 0 + for i in range(0, len(prices) - 1): + min_price = min(prices[i], min_price) + profit = prices[i+1] - min_price + max_profit = max(profit, max_profit) + return max_profit \ No newline at end of file From cf36d77aeb77ad7a50763fd14735074efa58fd72 Mon Sep 17 00:00:00 2001 From: changhyumm Date: Thu, 18 Dec 2025 23:51:22 +0900 Subject: [PATCH 4/6] line indent --- best-time-to-buy-and-sell-stock/changhyumm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best-time-to-buy-and-sell-stock/changhyumm.py b/best-time-to-buy-and-sell-stock/changhyumm.py index 9a824aea99..ed574fb68e 100644 --- a/best-time-to-buy-and-sell-stock/changhyumm.py +++ b/best-time-to-buy-and-sell-stock/changhyumm.py @@ -6,4 +6,4 @@ def maxProfit(self, prices: List[int]) -> int: min_price = min(prices[i], min_price) profit = prices[i+1] - min_price max_profit = max(profit, max_profit) - return max_profit \ No newline at end of file + return max_profit From 6ae8b94c8556aff972ae41d36c75f46a3bbf2485 Mon Sep 17 00:00:00 2001 From: changhyumm Date: Sat, 20 Dec 2025 02:01:19 +0900 Subject: [PATCH 5/6] design-add-and-search-words-data-structure --- .../changhyumm.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 design-add-and-search-words-data-structure/changhyumm.py diff --git a/design-add-and-search-words-data-structure/changhyumm.py b/design-add-and-search-words-data-structure/changhyumm.py new file mode 100644 index 0000000000..d7329c240b --- /dev/null +++ b/design-add-and-search-words-data-structure/changhyumm.py @@ -0,0 +1,40 @@ +# prefix 기반으로 탐색할 수 있는 트라이노드 자료구조 활용 +class TrieNode: + def __init__(self): + self.children = {} + self.is_ending = False + +class WordDictionary: + + def __init__(self): + self.root = TrieNode() + + def addWord(self, word: str) -> None: + current_node = self.root + for char in word: + if char not in current_node.children: + current_node.children[char] = TrieNode() + current_node = current_node.children[char] + current_node.is_ending = True + + def search(self, word): + def dfs(node, index): + # 단어자리수만큼 왔고, 끝단어인경우 찾기 성공 + if index == len(word): + return node.is_ending + # 와일드카드인 경우 자식들 전부 탐색 + if word[index] == ".": + for child in node.children.values(): + if dfs(child, index+1): + return True + # 일반적인 경우 다음 자식 탐색 + if word[index] in node.children: + return dfs(node.children[word[index]], index+1) + return False + return dfs(self.root, 0) + + +# Your WordDictionary object will be instantiated and called as such: +# obj = WordDictionary() +# obj.addWord(word) +# param_2 = obj.search(word) \ No newline at end of file From c6f5295861f8dbb7987e13f51eed46208d02b1a0 Mon Sep 17 00:00:00 2001 From: changhyumm Date: Sat, 20 Dec 2025 02:49:39 +0900 Subject: [PATCH 6/6] longest-increasing-subsequence --- longest-increasing-subsequence/changhyumm.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 longest-increasing-subsequence/changhyumm.py diff --git a/longest-increasing-subsequence/changhyumm.py b/longest-increasing-subsequence/changhyumm.py new file mode 100644 index 0000000000..5c5fc00e63 --- /dev/null +++ b/longest-increasing-subsequence/changhyumm.py @@ -0,0 +1,14 @@ +class Solution: + def lengthOfLIS(self, nums: List[int]) -> int: + # dp[i] = nums[0]부터 nums[i]까지의 LIS 길이 + # 처음은 1 + n = len(nums) + dp = [1] * n + + for i in range(1, n): + for j in range(i): + if nums[j] < nums[i]: + # nums[i]가 더 큰 경우 길이 + 1 + dp[i] = max(dp[i], dp[j] + 1) + + return max(dp) # 전체 중 최대 \ No newline at end of file