Simple solution by using the Priorityqueue

  • 0

    Just using priorityqueue to solve this question

     static class sortnum implements Comparator<Integer> {
           public int compare(Integer one, Integer two) {
    			return two - one;
    public int findKthLargest(int[] nums, int k) {
            int res = 0;
            sortnum bigtosmall = new sortnum();
            PriorityQueue<Integer> sortqueue = new PriorityQueue<Integer>(nums.length,bigtosmall);
            for(int num : nums){
            int i = 0;
                res = sortqueue.poll();
            return res;

    Have fun :)

Log in to reply

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