将这些数字按大小排列,用队列即可
class Solution {
public:
int getUglyNumber(int n) {
if(n <= 1) return 1;
vector<int> f(n+1);
f[1] = 1;
int l = 1, mid = 1, r = 1;
for(int i = 2; i <= n; i++){
int a = f[l] * 2, b = f[mid] * 3, c = f[r] * 5;
f[i] = min(min(a,b),c);
if(f[i] == a) l++;
if(f[i] == b) mid++;
if(f[i] == c) r++;
}
return f[n];
}
};