[freemjstudio] WEEK 05 Solutions#2773
Open
freemjstudio wants to merge 1 commit into
Open
Conversation
Contributor
|
Contributor
📊 freemjstudio 님의 학습 현황이번 주 제출 문제
누적 학습 요약
문제 풀이 현황
🤖 이 댓글은 GitHub App을 통해 자동으로 작성되었습니다. 🔢 API 사용량 (gpt-5-nano)
|
Contributor
There was a problem hiding this comment.
🏷️ 알고리즘 패턴 분석
- 패턴: Greedy, Two Pointers
- 설명: 최초 풀이엔 시간 복잡도 문제로 비효율적이지만, 두 번째 풀이에서 매일 최소 가격을 갱신하며 현재 가격과의 차이를 비교하는 방식은 그리디 패턴의 전형으로, 한 번의 순회로 최적해를 구한다. 또한 1차원 배열을 좌우로 단순한 포인터처럼 다루는 접근으로 간주 가능하다.
📊 시간/공간 복잡도 분석
| 복잡도 | |
|---|---|
| Time | O(n) |
| Space | O(1) |
피드백: 첫 시도는 모든 가능한 구매 시점을 기반으로 최대 이익을 계산해 시간 복잡도가 O(n^2)로 비효율적이다. 두 번째 시도에서 최소 가격과 누적 이익을 추적해 선형 시간으로 해결한다.
개선 제안: 현재 구현이 적절해 보입니다.
💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!
dolphinflow86
self-requested a review
July 25, 2026 03:12
dolphinflow86
approved these changes
Jul 25, 2026
Comment on lines
+1
to
+21
| # first attempt - time out | ||
|
|
||
| class Solution: | ||
| def maxProfit(self, prices: List[int]) -> int: | ||
| max_profit = 0 | ||
| for i in range(len(prices)): | ||
| profit = max(prices[i:]) - prices[i] | ||
| max_profit = max(max_profit, profit) | ||
| return max_profit | ||
|
|
||
| # second attempt - greedy approach | ||
| class Solution: | ||
| def maxProfit(self, prices: List[int]) -> int: | ||
| max_profit = 0 | ||
| min_price = prices[0] | ||
|
|
||
| for i in range(len(prices)): | ||
| min_price = min(min_price, prices[i]) | ||
| profit = prices[i] - min_price | ||
| max_profit = max(max_profit, profit) | ||
| return max_profit |
Contributor
There was a problem hiding this comment.
타임아웃 과정부터 성공한 솔루션까지 같이 보여주셔서 비교하기 좋았습니다.
시간/공간 복잡도 분석도 주석으로 같이 해주시면 더 좋을 것 같아요!
수고하셨습니다.
parkhojeong
reviewed
Jul 25, 2026
Comment on lines
+14
to
+18
| max_profit = 0 | ||
| min_price = prices[0] | ||
|
|
||
| for i in range(len(prices)): | ||
| min_price = min(min_price, prices[i]) |
Contributor
There was a problem hiding this comment.
i가 0인 경우 불필요한 재계산이 되서 1부터 시작하면 명확할 거 같습니다.
parkhojeong
requested changes
Jul 25, 2026
parkhojeong
left a comment
Contributor
There was a problem hiding this comment.
프로젝트 주차 설정과 pr 체크리스트도 확인 부탁드립니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!