-
-
Notifications
You must be signed in to change notification settings - Fork 362
[sangbeenmoon] WEEK 04 Solutions #2756
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
09f1ea0
745f661
94823b2
79a9055
667ffe0
912181e
c0c19ab
9a46ec6
b3a3b27
eb24f57
41c043e
b186a75
90bc4ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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(log n) |
| Space | O(1) |
피드백: 마지막 종료 조건이 명시적이지 않으나 일반적인 회전 배열 이진 탐색 패턴과 일치한다.
개선 제안: 특정 예외 케이스(중간값이 경계에 위치하는 경우)에 대한 명확한 처리 주석을 추가하면 가독성이 높아진다.
풀이 2: Solution.findMin (second solution) — Time: O(log n) / Space: O(1)
| 복잡도 | |
|---|---|
| Time | O(log n) |
| Space | O(1) |
피드백: 조건 비교를 통해 경계를 엄밀하게 좁히도록 구현되어 있다.
개선 제안: 동일 로직의 중복 제거를 통해 코드 중복을 줄이면 좋다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,25 @@ def findMin(self, nums: List[int]) -> int: | |
| right = mid | ||
|
|
||
| return nums[left] | ||
|
|
||
| # ----------- | ||
|
|
||
| # TC : O(logN) | ||
| # SC : 1 | ||
|
|
||
| class Solution: | ||
| def findMin(self, nums: List[int]) -> int: | ||
|
|
||
| left = 0 | ||
| right = len(nums) - 1 | ||
| mid = (left + right) // 2 | ||
|
Comment on lines
+32
to
+34
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. 이 부분 mid 할당은 중복으로 보여서 지워도 될 거 같습니다. |
||
|
|
||
| while left < right: | ||
| mid = (left + right) // 2 | ||
|
|
||
| if nums[mid] > nums[right]: | ||
|
Comment on lines
+36
to
+39
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. 탐색 중간에 정답인 경우 미리 리턴해보도록 해보셔도 좋을 거 같습니다. |
||
| left = mid + 1 | ||
| else: | ||
| right = mid | ||
|
|
||
| return nums[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 * 4^L) |
| Space | O(m * n) |
피드백: 백트래킹과 방문 기록을 통해 중복 경로를 제거하지만 최악의 경우 지수적 시간 복잡도가 발생할 수 있다.
개선 제안: 효율을 위해 감소된 상태 공간에서의 가지치기 조건 강화와 시간 복잡도 분석 명시가 필요하다.
풀이 2: Solution.exist (두 번째 구현) — Time: O(m * n * 4^L) / Space: O(m * n)
| 복잡도 | |
|---|---|
| Time | O(m * n * 4^L) |
| Space | O(m * n) |
피드백: 각 위치에서 시작해 DFS를 진행하고 종료 조건을 명확히 처리한다.
개선 제안: 반복적 구현이나 최적화된 가지치기, 사전 인덱스 매핑 등을 통해 성능을 개선할 수 있다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
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.
요거 돌려보니 3000ms 정도 나오는데 최적화 좀더 해보셔도 좋을 거 같습니다.
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
풀이 1:
Solution.coinChange (first implementation)— Time: O(amount * len(coins)) / Space: O(amount)피드백: 점화식을 재귀로 풀고 캐시를 사용해 중복 계산을 줄였지만 amount에 비례한 재귀 깊이가 필요하며, 최악의 경우 지수적 탐색을 피하기 어렵다.
개선 제안: 동적계획법의 순수한 바텀업(Bottom-Up) 접근이나 BFS 기반 풀이로 시간복잡도를 개선할 수 있다.
풀이 2:
Solution.coinChange (second implementation)— Time: O(amount * len(coins)) / Space: O(amount)피드백: 초기화된 memo에 목표 금액과 관련된 중간 결과를 저장해 중복 계산을 줄인다.
개선 제안: 반복적 DP(Bottom-Up)로 구현하면 함수 재귀 호출 오버헤드를 줄일 수 있다.