C++ Optimized Solution
\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n          int res[n];\n         res[0]=1;    // 2^0*3^0*5^0\n        \n        int i2=0,i3=0,i5=0; 
```\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n          int res[n];\n         res[0]=1;    // 2^0*3^0*5^0\n        \n        int i2=0,i3=0,i5=0; //indexes\n        \n        \n        for(int i=1;i<n;i++)\n        {\n            int next2 =  2*res[i2];  //next multiple of 2\n            int next3 =  3*res[i3];  //next multiple of 3\n            int next5 =  5*res[i5];  //next multiple of 5\n            \n            int next = min(next2, min(next3,next5));\n            \n            res[i]=next;\n            \n            if(next==next2)\n                i2++;\n            if(next==next3)\n                i3++;\n            if(next==next5)\n                i5++;\n            \n            \n        }\n        return res[n-1]; \n    }\n};\nif Helpful Please like and Upvoke\n```
[]