"""Leetcode 215. Kth Largest Element in an Array
Medium

URL: https://leetcode.com/problems/kth-largest-element-in-an-array/

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.

Example 1:
Input: [3,2,1,5,6,4] and k = 2
Output: 5

Example 2:
Input: [3,2,3,1,2,4,5,5,6] and k = 4
Output: 4

Note: 
You may assume k is always valid, 1 <= k <= array's length.
"""

class Solution(object):
    def findKthLargest(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        pas


def main():
    pass


if __name__ == '__main__':
    main()

@@ -482,168 +482,1030 @@
 def 
-findKthLargest(self, nums, k):%0A        %22%22%22%0A        :type nums: List%5Bint%5D%0A        :type k: int%0A        :rtype: int%0A        %22%22%22%0A        pas%0A%0A%0Adef main():%0A    pass
+quick_sort(self, nums):%0A        if len(nums) %3C= 1:%0A            return nums%0A%0A        pivot = nums%5Blen(nums) // 2%5D%0A%0A        left_nums = %5Bn for n in nums if n %3C pivot%5D%0A        mid_nums = %5Bn for n in nums if n == pivot%5D%0A        right_nums = %5Bn for n in nums if n %3E pivot%5D%0A%0A        return self.quick_sort(left_nums) + mid_nums + self.quick_sort(right_nums)%0A%0A    def findKthLargest(self, nums, k):%0A        %22%22%22%0A        :type nums: List%5Bint%5D%0A        :type k: int%0A        :rtype: int%0A%0A        Find the Kth largest by quick sort algorithm.%0A%0A        Time complexity: O(n*logn), where n is the length of nums.%0A        Space complexity: O(n).%0A        %22%22%22%0A        sorted_nums = self.quick_sort(nums)%0A        return sorted_nums%5B-k%5D%0A%0A%0Adef main():%0A    # Input: %5B3,2,1,5,6,4%5D and k = 2%0A    # Output: 5%0A    nums = %5B3, 2, 1, 5, 6, 4%5D%0A    k = 2%0A    print Solution().findKthLargest(nums, k)%0A%0A    # Input: %5B3,2,3,1,2,4,5,5,6%5D and k = 4%0A    # Output: 4%0A    nums = %5B3, 2, 3, 1, 2, 4, 5, 5, 6%5D%0A    k = 4%0A    print Solution().findKthLargest(nums, k)
 %0A%0A%0Ai

Complete sol by quick sort alg.