Simple Solution using PriorityQueue


  • 0
    7

    """
    public class Solution {
    public int findKthLargest(int[] nums, int k) {
    PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
    for(int a: nums){
    if(queue.size()<k){
    queue.add(a);
    }else{
    if(a<queue.peek()){

                }else{
                    queue.poll();
                    queue.add(a);
                }
                
            }
        }
        return queue.poll();
    }
    

    }

    """


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.