Skip to content

Latest commit

 

History

History
16 lines (14 loc) · 382 Bytes

File metadata and controls

16 lines (14 loc) · 382 Bytes
// simple PriorityQueue problem
public int findKthLargest(int[] nums, int k) {
    PriorityQueue<Integer> minPQ = new PriorityQueue<Integer>
        ((a, b) -> Integer.compare(a, b));

    for (int n : nums) {
        minPQ.add(n);
        if (minPQ.size() > k) {
            minPQ.poll();
        }            
    }
    return minPQ.poll();        
}