-
-
Notifications
You must be signed in to change notification settings - Fork 358
[chapse57] Week 1 #2661
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
[chapse57] Week 1 #2661
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,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 | ||
|
Comment on lines
+7
to
+11
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. 단순 중복 찾기는 Set을 활용할 수 있습니다. O(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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 해시맵으로 빈도수 저장 후 정렬하는 과정이 시간 복잡도를 결정하며, 정렬은 O(n log n)입니다. 공간은 빈도수 저장을 위한 해시맵과 정렬 결과를 위한 리스트입니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| 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) | ||
|
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. AI가 말한 것처럼 구현은 좋습니다. 다만 정렬 없이 최적화 하는 방법도 생각해보면 좋을 것 같네요. (e.g. 빈도 값을 배열 인덱스로 사용) |
||
|
|
||
| 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 | ||
|
|
||
|
|
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 이중 루프를 사용하여 모든 쌍을 비교하므로 시간 복잡도는 제곱에 비례하며, 공간은 상수입니다.
개선 제안: 현재 구현이 적절해 보입니다.