classSolution: deffindKthLargest(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ defpartition(nums, lo, hi): i = lo + 1 j = hi whileTrue: while i <= hi and nums[i] < nums[lo]: i += 1 while j > lo and nums[j] > nums[lo]: j -= 1 if i >= j: break nums[i], nums[j] = nums[j], nums[i] i += 1 j -= 1 nums[lo], nums[j] = nums[j], nums[lo] return j lo = 0 hi = len(nums) - 1 k = len(nums) - k while lo < hi: j = partition(nums, lo, hi) if j < k: lo = j + 1 elif j > k: hi = j - 1 else: break return nums[k]