← 返回 twosigma 的题目列表Find kth Largest Element in Unsorted Array
类型:online_judge
twosigma
Given an unsorted array, find the kth largest element. Implement a function kth_largest_element(nums, k) to solve this problem.
Input
nums: An array of integers with a length range [1, 10^4] and elements in the range [-10^4, 10^4].
k: A positive integer representing the kth largest element to find, within the range [1, len(nums)].
Output
Return the kth largest element in the array.
Example
Example 1:
Input: nums = [3,2,1,5,6,4], k = 2 Output: 5
Example 2:
Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4
Example
Input
3,2,1,5,6,4
2