Skip to content

Commit 3d274dd

Browse files
committed
fix: DaleStudy#347 shift() -> pop()
1 parent 9a6d07f commit 3d274dd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

top-k-frequent-elements/suKyoung.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ function topKFrequentHeap(nums: number[], k: number): number[] {
9393
const num = Number(numStr);
9494

9595
heap.push([num, frequent]);
96-
heap.sort((a, b) => a[1] - b[1]);
96+
heap.sort((a, b) => b[1] - a[1]);
9797

9898
if (heap.length > k) {
99-
heap.shift();
99+
heap.pop();
100100
}
101101
}
102102

0 commit comments

Comments
 (0)