题解 | #寻找第K大#
寻找第K大
http://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
# -*- coding:utf-8 -*-
class Solution:
def qu(self,nums,s,e):
if s>e:
return
mid= nums[s]
low=s
high=e
while(low<high):
while low<high and nums[high]>mid:
high-=1
nums[low]=nums[high]
while low<high and nums[low]<=mid:
low+=1
nums[high]=nums[low]
nums[low]=mid
self.qu(nums,s,low-1)
self.qu(nums,low+1,e)
def findKth(self, a, n, K):
# write code here
self.qu(a,0,n-1)
return a[::-1][K-1]