题目:
思路:
https://zhuanlan.zhihu.com/p/59110615
代码:
public int findKthLargest(int[] nums, int k) {
PriorityQueue<Integer> queue = new PriorityQueue<>((o1, o2) -> o1 - o2);
for (int i = 0; i < nums.length; i++) {
if (queue.size() >= k) {
if (queue.peek() < nums[i]) {
queue.poll();
queue.add(nums[i]);
}
} else {
queue.add(nums[i]);
}
}
return queue.peek();
}