You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for _ in range(k):
topk.append(heapq.heappop(freqsHeap)[1])
여기서 k번 만큼 추출하는데 , 문제에서 원하는건 k번 등장하는 요소를 추출하는거와는 조금 다르지 않나요?
예를 들면 입력에서
nums = [1, 1, 1, 2, 2, 3] -> nums = [1, 1, 1, 2, 2, 3, 3] 변경하면 원하는 출력은
[1, 2, 3] 이 되야하는데 위에 언급된 방식은 k번 까지만 추출해서 [1, 2]가 나오는데요..
제가 뭘 잘못 이해한건가요?
Activity
likejazz commentedon Jan 9, 2022
책에는 문제의 제약 조건까지 구체적으로 명시하지 않았으나 리트코드의 문제 설명을 보면 하단에 제약사항이 나열되어 있습니다.
1 <= nums.length <= 10^5kis in the range[1, the number of unique elements in the array].여기를 보면 유니크 하다는 제약을 두고 있기 때문에 따라서 동일한 빈도 수는 존재하지 않습니다.