[14] N is the number of binary 1

class Solution {
    public int findKthLargest(int[] nums, int k) {
        PriorityQueue<Integer> h = new PriorityQueue<>((n1,n2)->n1-n2);
        for(int i:nums){
            h.add(i);
            if(h.size()>k){
                h.poll();
            }
        }
        return h.poll();
    }
}

Guess you like

Origin www.cnblogs.com/Jun10ng/p/12355136.html