题解 | #寻找第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]
全部评论

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
程序员饺子:正常 我沟通了200多个 15个要简历 面试2个 全投的成都的小厂。很多看我是27直接不会了😅
点赞 评论 收藏
分享
水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务