From 6f450483f6c7103cb9025bd3d2207c6c724d5673 Mon Sep 17 00:00:00 2001 From: jinah92 Date: Mon, 13 Jan 2025 14:38:53 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20week=206=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=ED=92=80=EC=9D=B4(222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-parentheses/jinah92.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 valid-parentheses/jinah92.py diff --git a/valid-parentheses/jinah92.py b/valid-parentheses/jinah92.py new file mode 100644 index 000000000..0be463ec6 --- /dev/null +++ b/valid-parentheses/jinah92.py @@ -0,0 +1,20 @@ +# O(s) 공간 복잡도 : 입력문자열 s 길이에 따라 최대 s 깊이의 stack 생성 +# O(s) 시간 복잡도 : 문자열 s 길이에 따라 for문 반복 +class Solution: + def isValid(self, s: str) -> bool: + stack = [] + pairs = {'[': ']', '(': ')', '{': '}'} + + for i, ch in enumerate(s): + if ch == '(' or ch == '{' or ch == '[': + stack.append(ch) + else: + # '(', '[', '{' 문자가 앞에 없이 ')', ']', '}' 문자가 오는 경우 + if not stack: + return False + lastCh = stack.pop() + # pair가 맞지 않는 문자인 경우 + if pairs[lastCh] != ch: + return False + # stack에 값이 비지 않은 경우, pair가 맞지 않음 + return not stack From 174a7e15dd4ab6956527908508443e0a1c12d031 Mon Sep 17 00:00:00 2001 From: jinah92 Date: Mon, 13 Jan 2025 22:30:41 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20week6=20=EB=AC=B8=EC=A0=9C=ED=92=80?= =?UTF-8?q?=EC=9D=B4=20(242)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- container-with-most-water/jinah92.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 container-with-most-water/jinah92.py diff --git a/container-with-most-water/jinah92.py b/container-with-most-water/jinah92.py new file mode 100644 index 000000000..68cebab3f --- /dev/null +++ b/container-with-most-water/jinah92.py @@ -0,0 +1,15 @@ +# O(1) spaces, O(N) times +class Solution: + def maxArea(self, height: List[int]) -> int: + max_area = 0 + start, end = 0, len(height)-1 + + while start != end: + # start, end 포인터에서 물의 넓이 계산 및 최대값 계산 + max_area = max((end-start)*min(height[start], height[end]), max_area) + if height[start] < height[end]: + start += 1 + elif height[start] >= height[end]: + end -= 1 + + return max_area From 33aac178db116c98467b8e6e3700f08563da38e7 Mon Sep 17 00:00:00 2001 From: jinah92 Date: Tue, 14 Jan 2025 13:18:06 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20week=206=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=ED=92=80=EC=9D=B4=20(257)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jinah92.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 design-add-and-search-words-data-structure/jinah92.py diff --git a/design-add-and-search-words-data-structure/jinah92.py b/design-add-and-search-words-data-structure/jinah92.py new file mode 100644 index 000000000..2995eb3f7 --- /dev/null +++ b/design-add-and-search-words-data-structure/jinah92.py @@ -0,0 +1,23 @@ +# 공간복잡도 O(n): dictionary 멤버로 set을 사용 +# 시간복잡도 O(n*p): 삽입연산은 O(1)을 사용 +import re + +class WordDictionary: + + def __init__(self): + self.dictionary = set() + + def addWord(self, word: str) -> None: + self.dictionary.add(word) + + def search(self, word: str) -> bool: + if '.' in word: + pattern = re.compile(word) + # O(n) times + for item in self.dictionary: + # O(p) times : 패턴의 길이(p) + if pattern.fullmatch(item): + return True + return False + else: + return word in self.dictionary From 47d944c1cbf7b2e2a40d133ca37b7b619029d52b Mon Sep 17 00:00:00 2001 From: jinah92 Date: Thu, 16 Jan 2025 13:35:49 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20week=206=20=EB=AC=B8=EC=A0=9C?= =?UTF-8?q?=ED=92=80=EC=9D=B4=20(272)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- longest-increasing-subsequence/jinah92.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 longest-increasing-subsequence/jinah92.py diff --git a/longest-increasing-subsequence/jinah92.py b/longest-increasing-subsequence/jinah92.py new file mode 100644 index 000000000..a85a94b39 --- /dev/null +++ b/longest-increasing-subsequence/jinah92.py @@ -0,0 +1,12 @@ +# 공간 복잡도: O(n) => nums 길이만큼 dp 배열 길이만큼의 공간 사용 +# 시간 복잡도: O(n^2) => 외부 반복문은 O(N), 내부 반복문은 O(N) 시간이 소요되므로 총 O(N*N) = O(N^2) 소요 +class Solution: + def lengthOfLIS(self, nums: List[int]) -> int: + dp = [1] * len(nums) + + for cur in range(1, len(nums)): + for prev in range(cur): + if nums[cur] > nums[prev]: + dp[cur] = max(dp[prev]+1, dp[cur]) + + return max(dp)