-
-
Notifications
You must be signed in to change notification settings - Fork 362
[chapse57] Week 3 #2722
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?
[chapse57] Week 3 #2722
Changes from 7 commits
c474203
9e53265
6895637
afde7ad
888fb59
9cb02e4
b21959a
0b463ca
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,21 @@ | ||
| class Solution(object): | ||
| def climbStairs(self, n): | ||
| """ | ||
| :type n: int | ||
| :rtype: int | ||
| """ | ||
|
|
||
|
|
||
| if n == 1: | ||
| return 1 | ||
| if n == 2: | ||
| return 2 | ||
| a = 1 | ||
| b = 2 | ||
|
|
||
| for i in range(n - 2): | ||
| c = a + b | ||
| a = b | ||
| b = c | ||
|
Comment on lines
+17
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. 공간복잡도 고려한 점은 좋습니다. 다만 변수명을 좀 더 구체적으로 작성해주시면 리뷰어 입장에서 검토하기 좋으니 고려해주시면 좋을 것 같습니다. |
||
| return c | ||
|
|
||
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 중첩 루프를 통해 모든 쌍을 비교하므로 시간 복잡도가 n^2이다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class Solution(object): | ||
| def containsDuplicate(self, nums): | ||
| """ | ||
| :type nums: List[int] | ||
| :rtype: bool | ||
| """ | ||
| for i in range(len(nums)): | ||
| for j in range(i+1,len(nums)): | ||
| if nums[i] == nums[j]: | ||
| return True | ||
| 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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 각 단어별로 정렬 cost가 존재하고 해시맵에 그룹을 저장한다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| class Solution(object): | ||
| def groupAnagrams(self, strs): | ||
| """ | ||
| :type strs: List[str] | ||
| :rtype: List[List[str]] | ||
| """ | ||
| seen = {} | ||
| for word in strs: | ||
| key = "".join(sorted(word)) | ||
| # key가 seen에 이미 있으면 → word 추가 | ||
| # 없으면 → 새로 만들기 | ||
| if key in seen: | ||
| seen[key].append(word) | ||
| else: | ||
| seen[key] = [word] | ||
| return list(seen.values()) | ||
|
|
|
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,22 @@ | ||
| class Solution(object): | ||
| def topKFrequent(self, nums, k): | ||
| """ | ||
| :type nums: List[int] | ||
| :type k: int | ||
| :rtype: List[int] | ||
| """ | ||
| count = {} | ||
| for n in nums: | ||
| if n in count: | ||
| count[n] +=1 | ||
| else: | ||
| count[n] =1 | ||
| # count.items()를 횟수 큰 순으로 정렬 | ||
| freq = sorted(count.items(), key=lambda x: x[1], reverse=True) | ||
|
|
||
| result = [] | ||
| for x in freq[:k]: | ||
| result.append(x[0]) | ||
| return result | ||
|
|
||
|
|
|
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,14 @@ | ||
| class Solution(object): | ||
| def twoSum(self, nums, target): | ||
| """ | ||
| :type nums: List[int] | ||
| :type target: int | ||
| :rtype: List[int] | ||
| """ | ||
| seen = {} | ||
| for i in range(len(nums)): | ||
| if (target - nums[i]) in seen: | ||
| return [seen[target - nums[i]],i] | ||
| seen[nums[i]] =i | ||
|
|
||
|
|
|
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(object): | ||
| def isAnagram(self, s, t): | ||
| """ | ||
| :type s: str | ||
| :type t: str | ||
| :rtype: bool | ||
| """ | ||
| return sorted(s) == sorted(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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 입력 n에 대해 상수 공간으로 마지막 두 값을 유지하며 반복으로 결과를 구한다.
개선 제안: 현재 구현이 적절해 보입니다.