Skip to content

Commit 89edeec

Browse files
authored
Merge pull request #924 from HodaeSsi/main
[HodaeSsi] week 06
2 parents 31704db + 34478e7 commit 89edeec

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# 시간 복잡도 : O(n)
2+
# 공간 복잡도 : O(1)
3+
# 문제 유형 : Two Pointer
4+
class Solution:
5+
def maxArea(self, height: List[int]) -> int:
6+
left, right = 0, len(height) - 1
7+
max_area = 0
8+
9+
while left < right:
10+
max_area = max(max_area, (right - left) * min(height[left], height[right]))
11+
if height[left] < height[right]:
12+
left += 1
13+
else:
14+
right -= 1
15+
16+
return max_area
17+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 문제유형 : Trie
2+
class WordDictionary:
3+
def __init__(self):
4+
self.trie = {}
5+
6+
# 시간 복잡도 : O(N)
7+
# 공간 복잡도 : O(N)
8+
def addWord(self, word: str) -> None:
9+
node = self.trie
10+
for char in word:
11+
if char not in node:
12+
node[char] = {}
13+
node = node[char]
14+
node['$'] = True
15+
16+
# 시간 복잡도 : O(m^N) (m : 철자의 종류, N : 문자열의 길이)
17+
def search(self, word: str) -> bool:
18+
return self.dfs(0, self.trie, word)
19+
20+
def dfs(self, i, node, word):
21+
if i == len(word):
22+
return '$' in node
23+
if word[i] == '.':
24+
for child in node.values():
25+
if isinstance(child, dict) and self.dfs(i + 1, child, word):
26+
return True
27+
if word[i] in node:
28+
return self.dfs(i + 1, node[word[i]], word)
29+
return False
30+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 시간 복잡도 : O(nlogn)
2+
# 공간 복잡도 : O(n)
3+
# 문제 유형 : DP, Binary Search
4+
class Solution:
5+
def lengthOfLIS(self, nums: List[int]) -> int:
6+
dp = []
7+
for num in nums:
8+
if not dp or num > dp[-1]:
9+
dp.append(num)
10+
else:
11+
left, right = 0, len(dp) - 1
12+
while left < right:
13+
mid = left + (right - left) // 2
14+
if dp[mid] < num:
15+
left = mid + 1
16+
else:
17+
right = mid
18+
dp[right] = num
19+
return len(dp)
20+

spiral-matrix/HodaeSsi.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 시간 복잡도 : O(m * n)
2+
# 공간 복잡도 : O(1)
3+
# 문제 유형 : 구현
4+
class Solution:
5+
def spiralOrder(self, matrix: List[List[int]]) -> List[int]:
6+
row, col = len(matrix), len(matrix[0])
7+
up, down, left, right = 0, row - 1, 0, col - 1
8+
result = []
9+
while True:
10+
for i in range(left, right + 1):
11+
result.append(matrix[up][i])
12+
up += 1
13+
if up > down:
14+
break
15+
for i in range(up, down + 1):
16+
result.append(matrix[i][right])
17+
right -= 1
18+
if right < left:
19+
break
20+
for i in range(right, left - 1, -1):
21+
result.append(matrix[down][i])
22+
down -= 1
23+
if down < up:
24+
break
25+
for i in range(down, up - 1, -1):
26+
result.append(matrix[i][left])
27+
left += 1
28+
if left > right:
29+
break
30+
return result
31+

valid-parentheses/HodaeSsi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# 시간 복잡도 : O(n)
2+
# 공간 복잡도 : O(n)
3+
# 문제 유형 : Stack
4+
class Solution:
5+
def isValid(self, s: str) -> bool:
6+
stack = []
7+
8+
for char in s:
9+
if char in (')', '}', ']'):
10+
if not stack or stack.pop() != {')': '(', '}': '{', ']': '['}[char]:
11+
return False
12+
else:
13+
stack.append(char)
14+
15+
return not stack
16+

0 commit comments

Comments
 (0)