-
-
Notifications
You must be signed in to change notification settings - Fork 358
[Yiseull] WEEK 01 solutions #2665
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
4a9f95d
f173778
23487fb
82f4521
1659154
9f3f0b1
f87bd6d
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,3 @@ | ||
| class Solution: | ||
| def containsDuplicate(self, nums: List[int]) -> bool: | ||
| return len(nums) != len(set(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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 각 수에 대해 시작점 여부를 확인하고, 시작점인 경우에만 연속 길이를 확장합니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| class Solution: | ||
| def longestConsecutive(self, nums: List[int]) -> int: | ||
| answer = 0 | ||
| numsSet = set(nums) | ||
| for num in numsSet: | ||
| if num - 1 in numsSet: | ||
| continue | ||
|
|
||
| size = 1 | ||
| while num + 1 in numsSet: | ||
| size += 1 | ||
| num += 1 | ||
|
|
||
| answer = max(answer, size) | ||
|
|
||
| return answer |
|
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. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 해시맵으로 빈도수를 구하고 최소 힙을 이용해 k개를 유지하는 방식으로 동작합니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| from collections import Counter | ||
|
|
||
| class Solution: | ||
| def topKFrequent(self, nums: List[int], k: int) -> List[int]: | ||
| # return [key for key, counter in Counter(nums).most_common(k)] | ||
|
|
||
| # counter = {} | ||
| # for num in nums: | ||
| # if num in counter: | ||
| # counter[num] += 1 | ||
| # continue | ||
| # counter[num] = 1 | ||
| # | ||
| # return [key for key, counter in sorted(counter.items(), key=lambda x: -x[1])[0:k]] | ||
|
|
||
| counter = {} | ||
| for num in nums: | ||
| if num in counter: | ||
| counter[num] += 1 | ||
| continue | ||
| counter[num] = 1 | ||
|
|
||
| heap = [(-v, k) for k, v in counter.items()] | ||
| heapify(heap) | ||
|
|
||
| answer = [] | ||
| for _ in range(k): | ||
| answer.append(heappop(heap)[1]) | ||
|
|
||
| return answer |
|
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,7 @@ | ||
| class Solution: | ||
| def twoSum(self, nums: List[int], target: int) -> List[int]: | ||
| numMap = {} | ||
| for i, num in enumerate(nums): | ||
| if target - num in numMap: | ||
| return [numMap[target- num], i] | ||
| numMap[num] = 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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 정수 배열의 중복 여부를 빠르게 확인하기 위해 모든 원소를 집합에 담아 크기 비교를 수행합니다.
개선 제안: 현재 구현이 적절해 보입니다.