Description
Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
Examples
Input:
nums = [3,2,1,5,6,4], k = 2Output:
5Explanation:
The 2nd largest element is 5.
Input:
nums = [3,2,3,1,2,4,5,5,6], k = 4Output:
4Explanation:
The 4th largest element is 4.
Input:
nums = [7, 10, 4, 3, 20, 15], k = 3Output:
10Explanation:
When sorted in descending order: [20, 15, 10, 7, 4, 3]. The 3rd largest element is 10.
Constraints
- •
1 ≤ k ≤ nums.length ≤ 10⁵ - •
-10⁴ ≤ nums[i] ≤ 10⁴