Merge pull request #987 from Dewittt/patch-1

Update 0347.前K个高频元素.md
This commit is contained in:
程序员Carl
2022-01-08 18:31:06 +08:00
committed by GitHub

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