← 返回 meta 的题目列表Kth Largest Element in an Array
类型:online_judge
Given an integer array nums and an integer k, return the k-th largest element in the array.
Note: it is the k-th largest in sorted order, not the k-th distinct element.
Constraints:
1 <= len(nums) <= 2e5
-1e9 <= nums[i] <= 1e9
1 <= k <= len(nums)
Target complexity: expected O(n) (or acceptable O(n log k)), with low extra space.
Examples:
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
Example
Input
nums=[3,2,1,5,6,4]
k=2
Output
5