DP || C++ || Faster
Upvote, it motivates me \u270C\n\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n        vector<int> dp(n);\n        int two = 0; // Maintain the th
***Upvote, it motivates me*** \u270C\n```\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n        vector<int> dp(n);\n        int two = 0; // Maintain the three pointers i.e. two , three , five\n        int three = 0;\n        int five = 0;\n        \n        dp[0] = 1;\n        for(int i = 1 ; i < n ; i++){\n            int two_multiple = 2 * dp[two];\n            int three_multiple = 3 * dp[three];\n            int five_multiple = 5 * dp[five];\n            \n            dp[i] = min(two_multiple , min(three_multiple , five_multiple)); \n            if(dp[i] == two_multiple){\n                two++;\n            }\n            if(dp[i] == three_multiple){\n                three++;\n            }\n            if(dp[i] == five_multiple){\n                five++;\n            }\n        }\n        return dp[n - 1];\n    }\n};\n```
[]