LeetCode[215] 数组中的第K个最大元素


Related Topics:
“数组”: https://leetcode.com/tag/array/
“分治”: https://leetcode.com/tag/divide-and-conquer/
“快速选择”: https://leetcode.com/tag/quickselect/
“排序”: https://leetcode.com/tag/sorting/
“堆(优先队列)”: https://leetcode.com/tag/heap-priority-queue/
Similar Questions:
“摆动排序 II”: https://leetcode.com/problems/wiggle-sort-ii/
“前 K 个高频元素”: https://leetcode.com/problems/top-k-frequent-elements/
“第三大的数”: https://leetcode.com/problems/third-maximum-number/
“数据流中的第 K 大元素”: https://leetcode.com/problems/kth-largest-element-in-a-stream/
“最接近原点的 K 个点”: https://leetcode.com/problems/k-closest-points-to-origin/

Problem:

给定整数数组 nums 和整数 k,请返回数组中第 **k** 个最大的元素。

请注意,你需要找的是数组排序后的第 k 个最大的元素,而不是第 k 个不同的元素。

示例 1:

1
2
输入: [3,2,1,5,6,4] 和 k = 2
输出: 5

示例 2:

1
2
输入: [3,2,3,1,2,4,5,5,6] 和 k = 4
输出: 4

提示:

  • 1 <= k <= nums.length <= 104
  • -104 <= nums[i] <= 104
Read more