← 返回 meta 的题目列表Find Kth Largest Element in Array Efficiently
类型:online_judge
meta
Given an integer array nums and an integer k, write a function to return the kth largest element in the array. Note that you need to consider optimizing both time and space complexity.
Input/Output specifications
Input: An integer array nums and an integer k, where 1 <= k <= nums.length <= 10^4 and -10^4 <= nums[i] <= 10^4
Output: The kth largest element in the array
Example
Input: nums = [3,2,1,5,6,4], k = 2
Output: 5
Input: nums = [3,2,3,1,2,4,5,5,6], k = 4
Output: 4
Hint
k is always valid and 1 ≤ k ≤ nums.length.
Example
Input
6
3 2 1 5 6 4
2