-
-
Notifications
You must be signed in to change notification settings - Fork 361
[chapse57] Week 2 #2689
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 2 #2689
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 |
|
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 중첩 루프를 통해 모든 쌍을 검사하므로 최악의 경우 모든 쌍을 비교합니다.
개선 제안: 현재 구현이 적절해 보입니다.