C++ easy solution O(n) time
```\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n        int dp[n];\n        dp[0]=1;\n        int L1=0,L2=0,L3=0;\n        for(int i=1;i<n;i++)\
```\nclass Solution {\npublic:\n    int nthUglyNumber(int n) {\n        int dp[n];\n        dp[0]=1;\n        int L1=0,L2=0,L3=0;\n        for(int i=1;i<n;i++)\n        {\n            dp[i]=min(2*dp[L1], min(3*dp[L2],5*dp[L3]));\n            \n            if(dp[i]==2*dp[L1])\n                L1++;\n            if(dp[i]==3*dp[L2])\n                L2++;\n            if(dp[i]==5*dp[L3])\n                L3++;\n            \n        }\n        return dp[n-1];\n        \n    }\n};
[]