-
-
Notifications
You must be signed in to change notification settings - Fork 360
[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 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,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 | ||
| 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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 0의 존재 여부에 따라 분기해 올바른 결과를 도출합니다. 한 번의 순회로 곱을 누적하고, 0의 개수에 따라 정답을 구성합니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| class Solution: | ||
| def productExceptSelf(self, nums: List[int]) -> List[int]: | ||
| product = 1 | ||
| zero_pos = set() | ||
|
|
||
| for i in range(len(nums)): | ||
| num = nums[i] | ||
| if num != 0: | ||
| product *= num | ||
| else: | ||
| zero_pos.add(i) | ||
|
|
||
| if len(zero_pos) >= 2: | ||
| return [0 for num in nums] | ||
| elif len(zero_pos) == 1: | ||
| return [0 if i not in zero_pos else product for i in range(len(nums))] | ||
| else: | ||
| return [int(product / num) for num in nums] |
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 길이 일치 여부를 먼저 확인하고, 각 문자에 대해 증가/감소를 누적합니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| 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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 최초 시도에서 이중 루프를 통해 조합을 누적 계산하므로 시간복잡도가 n에 대해 제곱으로 증가합니다.
개선 제안: 현재 구현이 적절해 보입니다.