Skip to content

Conversation

Jeldo
Copy link
Contributor

@Jeldo Jeldo commented Dec 7, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@Jeldo Jeldo added the py label Dec 7, 2024
@Jeldo Jeldo requested a review from 5YoonCheol December 7, 2024 12:22
@Jeldo Jeldo self-assigned this Dec 7, 2024
@Jeldo Jeldo requested a review from a team as a code owner December 7, 2024 12:22
Copy link
Contributor

@EgonD3V EgonD3V left a 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분의 시간복잡도는 O(n log k)가 맞지 않을까 싶습니다.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이 부분에서 O(n log k) 시간이 걸릴 것 같네요?

Copy link
Contributor Author

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를 더 명확하게 나타내야겠네요 😅

Comment on lines +7 to +9
if n - 1 not in nums_set:
length = 0
while n + length in nums_set:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

레퍼런스 카운팅에서는 효율적이겠지만, 인터뷰라면 이 임시 객체들의 의미를 물어볼 것 같습니다.

@Jeldo Jeldo merged commit b8b7c86 into DaleStudy:main Dec 8, 2024
3 checks passed
@DaleSeo
Copy link
Member

DaleSeo commented Dec 8, 2024

@Jeldo 3기 첫 번째 답안 병합 축하드려요! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants