java priorityqueue solution

  • 0
     import java.util.*;
    public class Solution {
    public int findKthLargest(int[] nums, int k) {
       PriorityQueue<Integer> q = new PriorityQueue<Integer>();
       for(int i=0;i<nums.length;i++)
           q.add(new Integer(nums[i]));
       int size = nums.length;
       for(int i=size-k;i>0;i--)
      return q.poll().intValue();


Log in to reply

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