n刷,不会
https://leetcode-cn.com/problems/chou-shu-lcof/
class Solution {
public int nthUglyNumber(int n) {
int[] dp=new int[n];
int a=0,b=0,c=0;
dp[0]=1;
for(int i=1;i<n;i++){
int n2=dp[a]*2;
int n3=dp[b]*3;
int n5=dp[c]*5;
dp[i]=Math.min(Math.min(n2,n3),n5);
if(dp[i]==n2) a++;
if(dp[i]==n3) b++;
if(dp[i]==n5) c++;
//此时的数2,3,5的公倍数,所以要用if判断每一个,而不是if else
}
return dp[n-1];
}
}
时间复杂度O(N) 空间复杂度O(N)