Title Link: https://leetcode.com/problems/kth-largest-element-in-an-array/
Topic:
Find the kth largest element in an unsorted array. Note that it was the kth largest element in the sorted order and not the kth distinct element.
For example,
Given [3,2,1,5,6,4] and k = 2, return 5.
Note:
You may assume k are always valid, 1≤k≤array ' s length.
Ideas:
1, fast row, Time complexity O (NLOGN)
2. Division and Metallurgy. Divide by the fast line, the division of recursion. Each partition can be used to determine the position of an element and to know the number of elements smaller than that element. Visual time complexity of the worst O (n^2), preferably O (1), average? No motivation to do it ... Wait to do
Algorithm:
public int findkthlargest (int[] nums, int k) { arrays.sort (nums); return nums[nums.length-k]; }
"Leetcode" Kth largest Element in an Array