-
-
Notifications
You must be signed in to change notification settings - Fork 362
[yuseok89] WEEK 06 Solutions #2786
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
Changes from all commits
bcb60aa
e5e9478
aebb139
8ea4676
e7fc5a3
b32fb5c
e1718c9
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,22 @@ | ||
| # TC: O(N) | ||
| # SC: O(1) | ||
| class Solution: | ||
| def maxArea(self, height: List[int]) -> int: | ||
| l = 0 | ||
| r = len(height) - 1 | ||
| max_height = max(height) | ||
| ans = 0 | ||
|
|
||
| while l < r: | ||
| ans = max(ans, min(height[l], height[r]) * (r - l)) | ||
|
|
||
| if ans > max_height * (r - l): | ||
| return ans | ||
|
|
||
| if height[l] < height[r]: | ||
| l += 1 | ||
| else: | ||
| r -= 1 | ||
|
|
||
| return ans | ||
|
|
|
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. 제 생각에 너무 좋은 코드인데요, Python의 타입 힌팅을 적극적으로 이제 활용해 보시면 코드의 가독성에 큰 긍정적 영향을 줄것이라고 생각해요!
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. 아 물론 개인적 의견이니 꼭 하실 필요는 없습니다!!!
Contributor
Author
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. 문제 푸는 코드를 쓰면서는 신경 안쓴 부분이었는데,
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 트라이 구조로 단어를 저장하고 와일드카드를 재귀로 확장 탐색한다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| class WordDictionary: | ||
|
|
||
| def __init__(self): | ||
| self.trie = {} | ||
|
|
||
| def addWord(self, word: str) -> None: | ||
| cur = self.trie | ||
|
|
||
| for c in word: | ||
| if c not in cur: | ||
| cur[c] = {} | ||
| cur = cur[c] | ||
|
|
||
| cur[0] = True | ||
|
|
||
| def search(self, word: str) -> bool: | ||
|
|
||
| n = len(word) | ||
|
|
||
| def rec(cur: dict, idx: int) -> bool: | ||
| if idx == n: | ||
| return 0 in cur | ||
|
|
||
| if word[idx] == '.': | ||
| for next in cur: | ||
| if next == 0: | ||
| continue | ||
| if rec(cur[next], idx + 1): | ||
| return True | ||
| return False | ||
| else: | ||
| if word[idx] in cur: | ||
| return rec(cur[word[idx]], idx + 1) | ||
| else: | ||
| return False | ||
|
|
||
| return rec(self.trie, 0) | ||
|
|
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 이분검색으로 LIS의 길이를 효율적으로 관리한다. 개선 제안: 현재 구현이 적절해 보입니다. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # TC: O(NlogN) | ||
| # SC: O(N) | ||
| class Solution: | ||
| def lengthOfLIS(self, nums: List[int]) -> int: | ||
| arr = [] | ||
|
|
||
| for num in nums: | ||
| if len(arr) == 0 or arr[-1] < num: | ||
| arr.append(num) | ||
| else: | ||
| idx = bisect_left(arr, num) | ||
| arr[idx] = num | ||
|
|
||
| return len(arr) | ||
|
|
|
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. 와 이건 코드를 아트의 경지로 올리셨군요 ㄷㄷㄷ 대단하십니다.
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 끝까지 각 원소를 한 번씩 방문하는 방식으로 구현되어 있다. 개선 제안: 현재 구현이 적절해 보입니다. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # TC: O(N*M) | ||
| # SC: O(N*M) | ||
| class Solution: | ||
| def spiralOrder(self, matrix: List[List[int]]) -> List[int]: | ||
|
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. 진짜 깔끔하게 푸셨네요. 리뷰하러 왔다가 배워갑니다..!!! |
||
| n = len(matrix) | ||
| m = len(matrix[0]) | ||
| ans = [] | ||
| row, col, dir = 0, -1, 1 | ||
|
|
||
| n -= 1 | ||
|
|
||
| while n >= 0 and m >= 1: | ||
| for i in range(0, m): | ||
| col += dir | ||
| ans.append(matrix[row][col]) | ||
|
|
||
| for i in range(0, n): | ||
| row += dir | ||
| ans.append(matrix[row][col]) | ||
|
|
||
| n -= 1 | ||
| m -= 1 | ||
| dir *= -1 | ||
|
|
||
| return ans; | ||
|
|
||
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 문자열을 한 번 순회하며 스택으로 매칭 여부를 판단한다. 개선 제안: 현재 구현이 적절해 보입니다. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # TC: O(N) | ||
| # SC: O(N) | ||
| class Solution: | ||
| def isValid(self, s: str) -> bool: | ||
| pars = {'(': ')', '{': '}', '[': ']'} | ||
| stack = [] | ||
|
|
||
| for c in s: | ||
| if c in pars: | ||
| stack.append(c) | ||
| else: | ||
| if not stack or pars[stack.pop()] != c: | ||
| return False | ||
|
|
||
| return len(stack) == 0 | ||
|
|
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 왼쪽/오른쪽 포인터를 한 칸씩만 이동시키며 최댓값을 갱신한다. 루프는 배열 길이에 비례해 수행된다.
개선 제안: 현재 구현이 적절해 보입니다.