215. Kth Largest Element in an Array
215. Kth Largest Element in an Array
Description
Difficulty: Medium
Related Topics: Array, Divide and Conquer, Sorting, Heap (Priority Queue), Quickselect
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?
Example 1:
1 | Input: nums = [3,2,1,5,6,4], k = 2 |
Example 2:
1 | Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 |
Constraints:
- 1 <= k <= nums.length <= 105
- -104 <= nums[i] <= 104
Hints/Notes
- 2023/08/27
- Priority queue
- Quick select
- No solution from 0x3F
Solution
Language: C++
Quick select
1 | class Solution { |
1 | class Solution { |