← 返回 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 that would be at position k in a descending sort).
Requirements:
Implement an algorithm to return the answer without fully sorting the entire array.
Input Format
Line 1: integer n (length of the array)
Line 2: n integers representing nums
Line 3: integer k
Output Format
Output one integer: the k-th largest element.
Constraints
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
1 <= k <= n
Example Input:
6
3 2 1 5 6 4
2
Output:
5
Example
Input
6
3 2 1 5 6 4
2
Output
5