-
-
Notifications
You must be signed in to change notification settings - Fork 362
[daehyun99] WEEK02 solutions #2687
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 2 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,20 @@ | ||
| class Solution: | ||
| def climbStairs(self, n: int) -> int: | ||
| one_count = n | ||
| two_count = 0 | ||
| total_count = 0 | ||
|
|
||
| while one_count >=0 and two_count >=0: | ||
| # 조합 | ||
| total = one_count + two_count | ||
|
|
||
| count = 1 | ||
| for i in range(two_count): | ||
| count *= total - i | ||
| for i in range(two_count, 0, -1): | ||
| count /= i | ||
| total_count += count | ||
|
|
||
| one_count -=2 | ||
| two_count +=1 | ||
|
Comment on lines
+2
to
+19
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. dp를 사용하시면 |
||
| return int(total_count) | ||
|
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. collections 의 Counter가 기본적으로 defaultdict(int) 처럼 없는 키값에 대해 0을 보낸다는것을 알고 계실까요?
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.
@alphaorderly
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 카운트 차이를 이용해 한 번의 순회로 결과를 판정한다. 간단하고 빠른 방법이다. 개선 제안: 필요 없을 때는 defaultdict 사용 대신 배열 인덱스 기반 카운트로 더 빠르게 구현 가능.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from collections import defaultdict | ||
| class Solution: | ||
| def isAnagram(self, s: str, t: str) -> bool: | ||
| count = defaultdict(int) | ||
|
|
||
| if len(s) != len(t): | ||
| return False | ||
|
|
||
| for s_, t_ in zip(s, t): | ||
| count[s_] += 1 | ||
| count[t_] -= 1 | ||
|
|
||
| for key, val in count.items(): | ||
| if val != 0: | ||
| return False | ||
| return True |
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 각 단계의 경우의 수를 상태로 유지해 빠르게 누적하는 방식으로 구현되었으나, 현재 구현은 직관적이지 않을 수 있다.
개선 제안: 속도와 가독성을 위해 간단한 피보나치 DP로 구현하거나, 공간을 더 절약하는 형태로 개선해 보세요.