-
-
Notifications
You must be signed in to change notification settings - Fork 195
[jeldo3] Week1 #646
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
[jeldo3] Week1 #646
Conversation
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.
Pythonic한 간결한 풀이가 좋았습니다. 다만 시간복잡도와 공간복잡도 분석을 해보시면 도움이 되실 것 같습니다.
# O(nlogn) | ||
def topKFrequent(self, nums: list[int], k: int) -> list[int]: | ||
ls = [(key, value) for key, value in Counter(nums).items()] # O(n) | ||
return [key for _, key in heapq.nlargest(n=k, iterable=ls)] # O(nlogn) |
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.
이 부분의 시간복잡도는 O(n log k)가 맞지 않을까 싶습니다.
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.
저도 이 부분에서 O(n log k)
시간이 걸릴 것 같네요?
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.
아 o(nlogk)가 맞습니다. big O내 size를 더 명확하게 나타내야겠네요 😅
if n - 1 not in nums_set: | ||
length = 0 | ||
while n + length in nums_set: |
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.
레퍼런스 카운팅에서는 효율적이겠지만, 인터뷰라면 이 임시 객체들의 의미를 물어볼 것 같습니다.
@Jeldo 3기 첫 번째 답안 병합 축하드려요! 🥇 |
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.