题解 | #丑数#

丑数

https://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b

#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 
# @param index int整型 
# @return int整型
#
class Solution:
    def GetUglyNumber_Solution(self , index: int) -> int:
        # write code here
        # res=[1,2,3,4,5,6,8,9,10,12]
        res=[1]
        a=b=c=0
        while len(res)<index:
            v=min(res[a]*2,res[b]*3,res[c]*5)
            res.append(v)
            if res[a]*2==v:
                a+=1
            if res[b]*3==v:
                b+=1
            if res[c]*5==v:
                c+=1
        return res[index-1] if index!=0 else 0

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-23 18:34
点赞 评论 收藏
分享
05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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