100% faster easy to understand c++ solution using dp
\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n        int dp[n+1];\n      dp[0]=0;\n      dp[1]=1;\n      int i2=1,i3=1,i5=1;\n      int next2=2;
```\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n        int dp[n+1];\n      dp[0]=0;\n      dp[1]=1;\n      int i2=1,i3=1,i5=1;\n      int next2=2;\n      int next3=3;\n      int next5=5;\n      int next_multiple=1;\n      for(int i=2;i<=n;i++)\n      {\n        next_multiple=min(next2,min(next3,next5));\n        dp[i]=next_multiple;\n        if(next_multiple==next2)\n          i2++,next2=dp[i2]*2;\n        if(next_multiple==next3)\n          i3++,next3=dp[i3]*3;\n        if(next_multiple==next5)\n          i5++,next5=dp[i5]*5;\n      }return next_multiple;\n    }\n};\ndo upvote if you find it useful....\n```
['Dynamic Programming', 'C', 'C++']