DP Solution | JAVA 2 ms
\nclass Solution {\n    public int nthUglyNumber(int n) {\n        int dp[] = new int[n+1]; \n        dp[0] = 0;\n        dp[1] = 1;\n        int p2 = 1 , p3 = 
```\nclass Solution {\n    public int nthUglyNumber(int n) {\n        int dp[] = new int[n+1]; \n        dp[0] = 0;\n        dp[1] = 1;\n        int p2 = 1 , p3 = 1 , p5 = 1;\n        \n        for(int i = 2 ; i <= n ; i++)\n        {\n            int next2 = dp[p2] * 2; \n            int next3 = dp[p3] * 3;\n            int next5 = dp[p5] * 5;\n            \n            int ans = Math.min(next2 , Math.min(next3 , next5)); \n            dp[i] = ans;\n            \n            if(ans == next2) p2++;\n            if(ans == next3) p3++;\n            if(ans == next5) p5++;\n        }\n        \n        return dp[n]; \n    }\n}\n```
['Dynamic Programming', 'Java']