-
-
Notifications
You must be signed in to change notification settings - Fork 361
[Yiseull] WEEK 02 solutions #2682
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
4a9f95d
f173778
23487fb
82f4521
1659154
9f3f0b1
f87bd6d
cb9db2b
4f952d7
8893b18
351c777
ba521a8
497e96c
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,11 @@ | ||
| class Solution: | ||
| def climbStairs(self, n: int) -> int: | ||
| if n == 1: return 1 | ||
|
|
||
| dp = [0 for _ in range(n + 1)] | ||
| dp[0], dp[1] = 1, 1 | ||
|
|
||
| for i in range(2, n + 1): | ||
| dp[i] = dp[i - 1] + dp[i - 2] | ||
|
|
||
| return dp[n] |
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 2회 순회를 통해 각 위치의 최종 곱을 계산하는 표준 접근으로 효율적이다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class Solution: | ||
| def productExceptSelf(self, nums: List[int]) -> List[int]: | ||
| n = len(nums) | ||
| answer = [1] | ||
|
|
||
| # answer[i] -> nums[i] 왼쪽 값들의 곱 | ||
| for i in range(1, n): | ||
| answer.append(answer[i - 1] * nums[i - 1]) | ||
|
|
||
| tmp = 1 | ||
| for i in range(n - 1, -1, -1): | ||
| answer[i] *= tmp | ||
| tmp *= nums[i] | ||
|
|
||
| return answer |
|
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를 이용해 간단하고 직관적으로 구현됐다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from collections import Counter | ||
|
|
||
| class Solution: | ||
| def isAnagram(self, s: str, t: str) -> bool: | ||
| return Counter(s) == Counter(t) |
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(n)피드백: 2 이상의 계단 수를 구하기 위해 dp 배열을 한 차례 순회하며 각 위치의 값을 계산합니다.
개선 제안: 현재 구현이 적절해 보입니다.
풀이 2:
Solution.climbStairs— Time: O(n) / Space: O(n)피드백: n까지의 순회를 통해 모든 중간값을 보존하며 결과를 얻습니다.
개선 제안: 현재 구현이 적절해 보입니다.