代码
class Solution {
public:
int nthUglyNumber(int n) {
int a = 0, b = 0, c = 0;
vector<int> uglyNumbers(n,0);
uglyNumbers[0] = 1;
for(int i = 1; i < n; i++){
uglyNumbers[i] = min(min(uglyNumbers[a]*2, uglyNumbers[b]*3), uglyNumbers[c]*5);
if(uglyNumbers[i] == uglyNumbers[a]*2) a++;
if(uglyNumbers[i] == uglyNumbers[b]*3) b++;
if(uglyNumbers[i] == uglyNumbers[c]*5) c++;
}
return uglyNumbers[n-1];
}
};