import java.util.*;
public class Solution {
public ArrayList<Integer> GetLeastNumbers_Solution(int [] input, int k) {
PriorityQueue<Integer> maxQueue = new PriorityQueue<>((o1,o2)->{return o2 - o1;});
if(input == null || input.length == 0){
return new ArrayList<>(maxQueue);
}
for(int i = 0; i < input.length; ++i){
maxQueue.add(input[i]);
if(maxQueue.size() > k){
maxQueue.poll();
}
}
return new ArrayList<>(maxQueue);
}
} 


京公网安备 11010502036488号