Skip to content

Commit

Permalink
Update 0347.前K个高频元素.md
Browse files Browse the repository at this point in the history
前k个,应该传入倒序的comparator
  • Loading branch information
Dewittt authored Jan 3, 2022
1 parent bb4e867 commit b36f675
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion problems/0347.前K个高频元素.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class Solution {
Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
// 根据map的value值正序排,相当于一个小顶堆
PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>((o1, o2) -> o1.getValue() - o2.getValue());
PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>((o1, o2) -> o2.getValue() - o1.getValue());
for (Map.Entry<Integer, Integer> entry : entries) {
queue.offer(entry);
if (queue.size() > k) {
Expand Down

0 comments on commit b36f675

Please sign in to comment.