You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class KthLargest {
PriorityQueue<Integer> queue;
int k = 0;
public KthLargest(int k, int[] nums) {
this.k = k;
queue = new PriorityQueue<>(k);
for (int num : nums) {
queue.add(num);
if (queue.size() > k) {
queue.poll();
}
}
}
public int add(int val) {
queue.add(val);
if (queue.size() > k) {
queue.poll();
}
return queue.peek();
}
}
/**
* Your KthLargest object will be instantiated and called as such:
* KthLargest obj = new KthLargest(k, nums);
* int param_1 = obj.add(val);
*/
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: