对Java的大顶堆和小顶堆错误进行了修改

This commit is contained in:
chenhaoran14
2022-01-20 01:15:23 +08:00
parent 728fe17a10
commit b124befd12

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) -> o2.getValue() - o1.getValue());
PriorityQueue<Map.Entry<Integer, Integer>> queue = new PriorityQueue<>((o1, o2) -> o1.getValue() - o2.getValue());
for (Map.Entry<Integer, Integer> entry : entries) {
queue.offer(entry);
if (queue.size() > k) {