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