-
-
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
Changes from 2 commits
3ac2ea0
8b4c4ee
25791b9
80911b4
c33c4f0
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 한 번의 순회를 통해 현재 가격과 최소 가격을 비교하며 최대 이익을 갱신합니다. 개선 제안: 현재 구현이 적절해 보입니다. |
| 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 일 거 같아요. 고민해보셔도 좋을 거 같습니다!
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가 생각보다 비용이 크더라구요
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. 두분 의견 감사합니다! if문으로 인라인 처리하면 함수 호출 오버헤드 등을 줄일 수 있겠네요. |
||
|
|
||
| return max_profit | ||
|
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. 리뷰 누락이 있어서 추가로 남깁니다.
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. c++ 습관이 자꾸 나오네요 ㅎㅎ str은 사용하지 않아야겠습니다. 두번째 방법도 한번 생각해볼게요! 꼼꼼하게 리뷰해주셔서 감사합니다 🙏 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # 1) Group words by their sorted form using defaultdict. While iterating the strs, sort each word and append original word to the corresponding list. After then convert dict to 2 dimensional list and return the list. | ||
| # TC: O(N*LlogL) where N is length of strs, L is max length of a word. | ||
| # SC: O(N*L) | ||
|
|
||
| class Solution: | ||
| def groupAnagrams(self, strs: List[str]) -> List[List[str]]: | ||
| groups = defaultdict(list) | ||
|
|
||
| for str in strs: | ||
| sorted_str = "".join(sorted(str)) | ||
| groups[sorted_str].append(str) | ||
|
|
||
| return list(groups.values()) |
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.
오! 네 문제 추천 감사합니다! 한번 풀어볼게요 👍