← 返回 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 (the element at index k when the array is sorted in descending order).
Requirements:
Return the value of the element, not the k-th distinct element.
State the time complexity of your approach.
Constraints
1 <= len(nums) <= 1e5
-1e4 <= nums[i] <= 1e4
1 <= k <= len(nums)
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
6
3 2 1 5 6 4
2
Output
5