← 返回 linkedin 的题目列表Kth Element (Find the k-th element)
类型:online_judge
Problem: Find the k-th largest element in an array
Given an integer array nums and an integer k, return the k-th largest element in the array (note: it is not the k-th distinct element).
Implement a function to solve this task.
Input
Line 1: integer n, the length of the array.
Line 2: n integers representing nums.
Line 3: integer k (1 <= k <= n).
Output
Print one integer: the k-th largest element in nums.
Constraints
1 <= n <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
Expected time complexity: average O(n) or O(n log k); keep extra space as low as possible.
Example
Example 1
Input:
6
3 2 1 5 6 4
2
Output:
5
Example 2
Input:
5
3 2 3 1 2
4
Output:
2
Example
Input
6
3 2 1 5 6 4
2
Output
5