Kth Largest Element in a Stream
找一个流中第k大的元素. 找大用min heap.
class KthLargest {
PriorityQueue<Integer> m;
int k;
public KthLargest(int k, int[] nums) {
this.k = k;
m = new PriorityQueue<>();
for(int n : nums)
m.add(n);
}
public int add(int val) {
m.add(val);
while(m.size() > k) {
m.poll();
}
return m.peek();
}
}