leetcode 剑指 Offer 49. 丑数
2021-02-17 本文已影响0人
flood_d
0.code
class Solution {
public int nthUglyNumber(int n) {
int a=0,b=0,c=0;
int[] d = new int[n];
d[0]=1;
for(int i=1;i<n;i++){
d[i] = Math.min(d[a]*2,Math.min(d[b]*3,d[c]*5));
if(d[i]==d[a]*2)a++;
if(d[i]==d[b]*3)b++;
if(d[i]==d[c]*5)c++;
}
return d[n-1];
}
}