-
-
Notifications
You must be signed in to change notification settings - Fork 361
[njngwn] WEEK 02 solutions #2676
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class Solution: | ||
| # dynamic programming with bottom-up | ||
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def climbStairs(self, n: int) -> int: | ||
| if n <= 2: return n | ||
| prev1, prev2 = 2, 1 | ||
|
|
||
| for i in range(3, n+1): | ||
| prev1, prev2 = prev2 + prev1, prev1 | ||
|
|
||
| return prev1 |
|
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,7 @@ | ||
| from collections import Counter | ||
|
|
||
| class Solution: | ||
| # Time Complexity: O(n), n: max(len(s), len(t)) | ||
| # Space Complexity: O(k), k: number of letters | ||
| def isAnagram(self, s: str, t: str) -> bool: | ||
| return Counter(s) == Counter(t) | ||
|
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. 안녕하세요 이번주 리뷰를 맡게되었습니다 :) Counter라는게 있군요? 엄청 깔끔하네요! 그런데 len로 길이가 다른 경우 리턴하도록 체크를 먼저 해 주면, 불필요하게 맵을 만드는 비용을 줄일 수 있을 것 같아요. |
||
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.climbStairs— Time: O(n) / Space: O(1)피드백: 두 단계의 합으로 현재의 경우의 수를 구하는 일반적인 DP 풀이입니다. 상수 공간으로 구현되어 효율적입니다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 2:
Solution— Time: O(n) / Space: O(k)피드백: 두 문자열의 문자 빈도를 세어 동일 여부를 판단하는 표준적인 방법입니다.
개선 제안: 현재 구현이 적절해 보입니다.