def quick_sort(self, nums, k): i = 0 for j in range(1,len(nums)): if nums[j] > nums[0]: i += 1 nums[i],nums[j] = nums[j],nums[i] nums[i],nums[0] = nums[0],nums[i] if i == k-1: return nums[i] elif i > k-1: return self.quick_sort(nums[:i], k) else: return self.quick_sort(nums[i+1:], k-i-1)
def findKthLargest(self, nums, k): """ :type nums: List[int] :type k: int :rtype: int """ if nums==None or len(nums)==0 or k<1: return -1 return self.quick_sort(nums, k)
评论系统未开启,无法评论!