题解 | #最小的K个数#
最小的K个数
http://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf
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); } }