class Solution {
public int[] getLeastNumbers(int[] arr, int k) {
PriorityQueue<Integer> heap = new PriorityQueue<Integer>();
for (int i=0; i < arr.length; i++) {
heap.add(arr[i]);
}
int[] ans = new int[k];
for (int i = 0; i < k; i++) {
ans[i] = heap.poll();
}
return ans;
}
}
没有思路,直接看答案,跟难度没关系,主要是没见过,想不到。