Skip to content

Latest commit

 

History

History
 
 

zuiXiaoDeKgeShuLcof

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

最小的k个数

LeetCode地址

程序

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;
    }
}

总结

没有思路,直接看答案,跟难度没关系,主要是没见过,想不到。