-
-
Notifications
You must be signed in to change notification settings - Fork 362
[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
Changes from 13 commits
4a9f95d
f173778
23487fb
82f4521
1659154
9f3f0b1
f87bd6d
cb9db2b
4f952d7
8893b18
351c777
ba521a8
497e96c
6bafe9b
4e4e371
6c17af8
db3afb5
ee76755
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,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. answer[0]을 1로 할당하니까 로직이 잘 읽히네요. 잘 봤습니다. 공간/시간 복잡도를 코드에 적어주시면 좋을 것 같아요!
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,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): | ||
|
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. 개인적으로 저는 이렇게 작성하는거를 선호합니다! for i in reversed(range(n)): |
||
| 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. 파이썬의 언어적인 특성을 잘 활용하신 것 같습니다! 저는 성능에 도움이 될 것 같아서, 아래와 같이 길이가 다를 경우 얼리리턴을 해주었습니다. 참고 부탁드립니다~ if len(s) != len(t):
return False
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.
공간 복잡도를 O(1)으로 최적화할 수 있을 것 같습니다!
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.
변수 2개로도 충분히 풀 수 있군요! 피드백 감사합니다~!