-
-
Notifications
You must be signed in to change notification settings - Fork 303
[WHYjun] WEEK 01 solutions #1978
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
Conversation
| return len(numsSet) | ||
|
|
||
| # Use priority queue to sort in O(n) | ||
| sorted = [] |
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.
sorted는 파이썬 내장 정렬 함수라, 같은 이름의 변수를 정의하면 함수 참조가 가려집니다.
이후에 sorted 호출 시 혼동을 일으킬 수 있으니, pq 같은 변수명을 사용하는게 좋을 것 같습니다.
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.
그렇네요. 인터뷰용으로만 쓰다 보니 이런 부분을 놓치네요. 감사합니다.
| for num in numsSet: | ||
| heapq.heappush(sorted, num) | ||
|
|
||
| prev = heapq.heappop(sorted) |
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.
힙큐를 이용해 단순 정렬을 원하시면 heapify로 힙을 구성한 뒤, sorted()로 정렬하는 편이 더 효율적이고, 단순 sorted(numSet)을 호출하셔도 동일한 결과를 얻으실 수 있으십니다.
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.
감사합니다. 일단 heapify로 해두었습니다. 기록용으로 heapq 풀이법 먼저 생각해두었던 것을 남겨둔 거라서요.
|
네~! 고생하셨습니다! |
haxr369
left a comment
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.
네! 고생하셨어요!
남은 한주 파이팅입니다!
답안 제출 문제
작성자 체크 리스트
In Review로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!