264. 丑数 II

编写一个程序,找出第 n 个丑数。

丑数就是质因数只包含 2, 3, 5 的正整数。

示例:

输入: n = 10
输出: 12
解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。
说明:  

1 是丑数。
n 不超过1690。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/ugly-number-ii

dp+三指针

class Solution:
    def nthUglyNumber(self, n: int) -> int:
        ugly=[1]*n
        base=[0]*3
        for i in range(1,n):
            a=ugly[base[0]]*2
            b=ugly[base[1]]*3
            c=ugly[base[2]]*5
            next=min(a,b,c)
            if next==a:base[0]+=1
            if next==b:base[1]+=1
            if next==c:base[2]+=1
            ugly[i]=next
        return ugly[-1]
原文地址:https://www.cnblogs.com/xxxsans/p/13773539.html