python做法| #最小的K个数#

最小的K个数

http://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf

# -*- coding:utf-8 -*-
class Solution:
    def GetLeastNumbers_Solution(self, tinput, k):
        # write code here
        n = len(tinput)
        if n<=k:return tinput
        if not k: return []
        res = tinput[0:k]
        maxi = res.index(max(res))
        for i in range(k,n):
            if tinput[i]<res[maxi]:res[maxi] = tinput[i];maxi = res.index(max(res))
        return res

大佬们帮我看看这个算是复杂度达到标准吗

全部评论

相关推荐

点赞 评论 收藏
分享
如题,只有过一段小厂实习经历,秋招会很吃亏吗?
KarlAllen_直通春招版:我也没大厂实习。今年大厂又扩招实习生。不知道秋招要怎么办了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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