美文网首页
2019-08-19 剑指 丑数

2019-08-19 剑指 丑数

作者: mztkenan | 来源:发表于2019-08-19 16:21 被阅读0次

12min

    def GetUglyNumber_Solution(self, index):
        if index<1:return None
        res=[1]
        p2,p3,p5=0,0,0
        for i in range(index):
            tmp=min(res[p2]*2,res[p3]*3,res[p5]*5)
            if tmp==res[p2]*2:p2+=1
            if tmp==res[p3]*3:p3+=1
            if tmp==res[p5]*5:p5+=1
            res.append(tmp)
        return res[index-1]

相关文章

  • 2019-08-19 剑指 丑数

    12min

  • [剑指offer] 丑数

    本文首发于我的个人博客:尾尾部落 题目描述 把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6...

  • 【剑指 offer】丑数

    1、题目描述 我们把只包含因子2、3和5的数称作丑数(Ugly Number)。 例如6、8都是丑数,但14不是,...

  • 剑指offer----丑数

    题目:把只包含因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含因子...

  • 【剑指Offer 34】丑数

    题目:我们把只包含因子2、3 和5 的数称作丑数(Ugly Number)。求从小到大的顺序的第1500个丑数。 ...

  • 【python】剑指offer,丑数?

    题目:把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含质...

  • 剑指Offer-丑数

    获取前N个丑数 如果一个数的素因子只有 2,3,5 ,我们称它为丑数,1 是第一个丑数, 要求按大小输出前N个丑数...

  • 剑指Offer--丑数

    https://bellick.github.io/2019/01/09/getUglyNumber/#more

  • 剑指Offer——丑数 Java

    题目描述 把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包...

  • 剑指offer--丑数

    题目:把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含质...

网友评论

      本文标题:2019-08-19 剑指 丑数

      本文链接:https://www.haomeiwen.com/subject/qwzssctx.html