My simple solution using PriorityQueue(JAVA)

  • 0

    public class Solution {

    public int findKthLargest(int[] a, int k) {
    PriorityQueue<Integer> q = new PriorityQueue<>(k, new Comparator<Integer>(){
    public int compare(Integer a, Integer b){
    return (int)a-b;
    int i = 0;
    for(; i< a.length; i++){
    if(q.size() > k) q.poll();
    return (int)q.peek();



Log in to reply

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