Update 0347.前K个高频元素.md

前k个,应该传入倒序的comparator
This commit is contained in:
Dewittt
2022-01-03 15:56:46 +08:00
committed by GitHub
parent bb4e867c35
commit b36f675599

View File

@ -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) {