Question
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
For example, Given [3,2,1,5,6,4] and k = 2, return 5.
Note: You may assume k is always valid, 1 ≤ k ≤ array's length.
Explanation
常考题。可以有三种方法:a. 直接sort,然后找到第k个。b.用一个heap来存,这种方法遇到最大top kth 也可以做,或者遇到不停更新的数组,需要不停add的情况时,可以用这个来存。会很有效率。c.用quick sort来找partition aray来找。
这三种方法都写在下面了,包括时间空间效率分析。