class Solution {
public int nthUglyNumber(int n) {
//采用dp的方法
//三个指针
int flag1 = 1, flag2 = 1, flag3 = 1;
int[] dp = new int[n + 1];
dp[1] = 1;
for (int i = 2; i <= n; i ++) {
int num1 = dp[flag1] * 2;
int num2 = dp[flag2] * 3;
int num3 = dp[flag3] * 5;
//最小
int ans = Math.min(num1, Math.min(num2, num3));
dp[i] = ans;
if (ans == num1)
flag1 ++;
if (ans == num2)
flag2 ++;
if (ans == num3)
flag3 ++;
}
return dp[n];
}
}