-
-
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
Open
dolphinflow86
wants to merge
5
commits into
DaleStudy:main
Choose a base branch
from
dolphinflow86:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−0
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3ac2ea0
best time to buy and sell stock solution
dolphinflow86 8b4c4ee
group anagrams solution
dolphinflow86 25791b9
encode and decode strings solution
dolphinflow86 80911b4
word break solution
dolphinflow86 c33c4f0
implement trie prefix tree solution
dolphinflow86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 한 번의 순회를 통해 현재 가격과 최소 가격을 비교하며 최대 이익을 갱신합니다. 개선 제안: 현재 구현이 적절해 보입니다. |
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
| 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) | ||
|
Comment on lines
+9
to
+11
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. 사소하지만 더 최적화 할 수 있는 부분은 min, max 일 거 같아요. 고민해보셔도 좋을 거 같습니다! |
||
|
|
||
| return max_profit | ||
Oops, something went wrong.
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.
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.
깔끔하게 잘 해결해 주셨네요!
best time to buy and sell stock, 즉 해당 문제는
뒤에 로마 숫자를 붙혀서 1, 2, 3, 4, 5 총 다섯종류가 있는데요
dp 연습하기에 정말 괜찮은 문제라고 생각해서
2번문제
II는 한번 풀어보시길 추천드려요!
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.
오! 네 문제 추천 감사합니다! 한번 풀어볼게요 👍