170. Kth Largest Element in an Array
MediumHeap
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. Can you solve it without sorting?
Examples
Input: [3,2,1,5,6,4] 2
Output: 5
Explanation: Sorted descending: 6,5,4,3,2,1 — the 2nd largest is 5.
Constraints
- 1 <= k <= nums.length <= 10^5
- -10^4 <= nums[i] <= 10^4
Loading...
Run checks all cases above. Submit evaluates all test cases.