Java | Simple | Clean
Slightly modified version of this solution\n Extended problem: LC 313. Super Ugly Number\n>T/S: O(n)/O(n)\n\npublic int nthUglyNumber(int n) {\n\tvar pairs = ne
* Slightly modified version of [this solution](https://leetcode.com/problems/ugly-number-ii/discuss/69385/Java-Easy-Understand-O(n)-Solution)\n* Extended problem: [LC 313. Super Ugly Number](https://leetcode.com/problems/super-ugly-number/discuss/4608324/Java-or-Reuse-264-or-Maths)\n>T/S: O(n)/O(n)\n```\npublic int nthUglyNumber(int n) {\n\tvar pairs = new int[][]{{2, 0}, {3, 0}, {5, 0}}; // pairs of (factor, factor pointer)\n\tvar uglies = new ArrayList<>(List.of(1));\n\n\twhile (uglies.size() < n) {\n\t\tvar nextUgly = Integer.MAX_VALUE;\n\t\t\n\t\tfor (var pair : pairs)\n\t\t\tnextUgly = Math.min(nextUgly, pair[0] * uglies.get(pair[1]));\n\n\t\tuglies.add(nextUgly);\n\t\t\n\t\tif (uglies.size() == n)\n\t\t\treturn nextUgly;\n\n\t\tfor (var pair : pairs)\n\t\t\tif (pair[0] * uglies.get(pair[1]) == nextUgly)\n\t\t\t\tpair[1]++;\n\t}\n\n\treturn 1;\n}\n```\n***Please upvote if this helps***
['Java']