DP approach | Java simple solution
java\npublic int nthUglyNumber(int n) {\n        TreeSet<Long> st = new TreeSet<>();\n        st.add((long)1);\n        int cnt = 0;\n        long ans = 1;\n   
```java\npublic int nthUglyNumber(int n) {\n        TreeSet<Long> st = new TreeSet<>();\n        st.add((long)1);\n        int cnt = 0;\n        long ans = 1;\n        for(;cnt != n;){\n            long ugly = st.pollFirst();\n            ans = ugly;\n            ++cnt;\n            st.add(2 * ugly);\n            st.add(3 * ugly);\n            st.add(5 * ugly);\n        }\n        return (int)ans;\n    }\n```
['Dynamic Programming', 'Java']