#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param a int整型一维数组 
# @param n int整型 
# @param K int整型 
# @return int整型
#
class Solution:
    def findKth(self , a: List[int], n: int, K: int) -> int:
        # write code here

        def quickSort(a, start, end):
            if start >= end:
                return 
            l = start
            r = end
            target = a[l]
            while l < r:
                while l < r and a[r] > target:
                    r -= 1
                a[l] = a[r]
                while l < r and a[l] <= target:
                    l += 1
                a[r] = a[l]
            a[l] = target

            # 第k大的元素,转为升序排列的元素a[n-K]
            if l == n-K:
                return target
            elif l < n-K:
                quickSort(a, l+1, end)
            elif l > n-K:
                quickSort(a, start, l-1)

        quickSort(a, 0, n-1)
        return a[n-K]