-
-
Notifications
You must be signed in to change notification settings - Fork 362
[sangbeenmoon] WEEK 06 Solutions #2790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| class Solution: | ||
| def maxArea(self, height: List[int]) -> int: | ||
|
|
||
| left = 0 | ||
| right = len(height) - 1 | ||
|
|
||
| answer = 0 | ||
|
|
||
| while left < right: | ||
| width = right - left | ||
| h = min(height[left], height[right]) | ||
| answer = max(answer, width * h) | ||
|
|
||
| if height[left] < height[right]: | ||
| left += 1 | ||
| else: | ||
| right -= 1 | ||
|
|
||
| return answer |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
풀이 1:
|
| 복잡도 | |
|---|---|
| Time | O(L) |
| Space | O(N) |
피드백: 문자별로 자식 노드를 구성하고 끝에 도달하면 is_end 를 True로 마킹한다.
개선 제안: 일반적인 순회 방식으로 재귀 깊이가 증가할 수 있어 스택 오버플로우 위험을 고려해 비재귀 구현도 검토해볼 수 있습니다.
풀이 2: WordDictionary.search — Time: O(Alphabet^k) / Space: O(H)
| 복잡도 | |
|---|---|
| Time | O(Alphabet^k) |
| Space | O(H) |
피드백: 점(.)을 사용한 모든 경로를 탐색하므로 최악의 경우 탐색 비용이 커질 수 있습니다.
개선 제안: 실제 사용에서 점(.)의 사용 비율이 낮다면 트라이의 가지 수를 줄이는 방향으로 최적화 가능.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| class WordDictionary: | ||
|
|
||
| def __init__(self): | ||
| self.children = {} | ||
| self.is_end = False | ||
|
|
||
|
|
||
|
|
||
| def addWord(self, word: str, i=0) -> None: | ||
| if i >= len(word): | ||
| self.is_end = True | ||
| return | ||
|
|
||
| target_char = word[i] | ||
|
|
||
| if target_char in self.children: | ||
| node = self.children[target_char] | ||
| node.addWord(word, i+1) | ||
| else: | ||
| node = WordDictionary() | ||
| self.children[target_char] = node | ||
| node.addWord(word, i+1) | ||
|
|
||
|
|
||
| def search(self, word: str, i=0) -> bool: | ||
| if i >= len(word): | ||
| return self.is_end | ||
|
|
||
| target_char = word[i] | ||
|
|
||
| if target_char == ".": | ||
| for child_node in self.children.values(): | ||
| if child_node.search(word,i+1) == True: | ||
| return True | ||
|
|
||
| if target_char in self.children: | ||
| node = self.children[target_char] | ||
| return node.search(word, i+1) | ||
| else: | ||
| node = WordDictionary() | ||
| return node.search(word, i+1) | ||
|
Comment on lines
+40
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이부분은 맞는 단어가 없다는거니까 return False를 하는게 더 맞지 않을까 생각해요! |
||
|
|
||
|
|
||
|
|
||
|
|
||
| # Your WordDictionary object will be instantiated and called as such: | ||
| # obj = WordDictionary() | ||
| # obj.addWord(word) | ||
| # param_2 = obj.search(word) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
풀이 1:
|
| 복잡도 | |
|---|---|
| Time | O(n log n) |
| Space | O(n) |
피드백: 이분 탐색을 이용한 LIS 배열 유지 방식으로 최적의 길이를 효율적으로 구한다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 2: Solution.lengthOfLIS — Time: O(n^2) / Space: O(n)
| 복잡도 | |
|---|---|
| Time | O(n^2) |
| Space | O(n) |
피드백: 직관적이지만 시간 복잡도가 커져 큰 입력에서 비효율적이다.
개선 제안: 필요 시 이분탐색 기반으로 전환하는 것을 권장.
풀이 3: Solution.lengthOfLIS — Time: O(n log n) / Space: O(n)
| 복잡도 | |
|---|---|
| Time | O(n log n) |
| Space | O(n) |
피드백: bisect_left를 사용하여 시퀀스의 적절한 위치를 업데이트한다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
풀이 1:
|
| 복잡도 | |
|---|---|
| Time | O(m*n) |
| Space | O(m*n) |
피드백: 방문 여부를 추적하며 한 방향으로 진행하고 벽에 닿으면 방향을 바꾼다.
개선 제안: DFS 방식은 스택 깊이가 큼에 따라 재귀 한계를 주의. 반복 구현으로 바꾸면 안전.
풀이 2: Solution.spiralOrder — Time: O(m*n) / Space: O(m*n)
| 복잡도 | |
|---|---|
| Time | O(m*n) |
| Space | O(m*n) |
피드백: 명시적으로 현재 위치와 방향을 관리하여 순환한다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 왼쪽/오른쪽 포인터를 한 칸씩 이동하며 현재 구간의 넓이를 갱신한다. 두 높이 중 작은 쪽을 늘리면 더 큰 넓이가 나올 수 있는 가능성을 남기고 버려진 부분을 제거한다.
개선 제안: 현재 구현이 적절해 보입니다.