-
-
Notifications
You must be signed in to change notification settings - Fork 361
[dolphinflow86] WEEK 05 Solutions #2762
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
|
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. 오! 네 문제 추천 감사합니다! 한번 풀어볼게요 👍 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # 1) Keep track of local minimum and use local minimum to update max profile while interating prices. | ||
| # TC: O(N) where N is the length of prices | ||
| # SC: O(1) | ||
| class Solution: | ||
| def maxProfit(self, prices: List[int]) -> int: | ||
| min_price = prices[0] | ||
| max_profit = 0 | ||
|
|
||
| for price in prices: | ||
| max_profit = max(max_profit, price - min_price) | ||
| min_price = min(min_price, price) | ||
|
|
||
| return max_profit |
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 초기 최소 가격을 설정하고 가격이 오를 때마다 이익을 갱신하는 단일 순회 방식이다.
개선 제안: 현재 구현이 적절해 보입니다.