C++ solution with O(n) time
class Solution {\npublic:\n        int nthUglyNumber(int n) {\n            int i=0;\n            int j=0;\n            int k=0;\n            vector v;\n        
class Solution {\npublic:\n        int nthUglyNumber(int n) {\n            int i=0;\n            int j=0;\n            int k=0;\n            vector<int> v;\n            v.push_back(1);\n        \n            while(v.size()!=n){\n                   int m=min(v[i]*2,min(v[j]*3,v[k]*5));\n\t\t   if(m==v[i]*2) i++;\n\t\t   if(m==v[j]*3) j++;\n\t\t   if(m==v[k]*5) k++;\n                   v.push_back(m);  \n            }\n            return v.back();\n        }\n};
[]