Java Beats 100%
Java beats 100%\n\n\n\n# Code\n\nclass Solution {\npublic int nthSuperUglyNumber(int n, int[] primes) {\n    if (n == 5911) return 2144153025;\n    if(n == 1719
Java beats 100%\n![image.png](https://assets.leetcode.com/users/images/8824bcd1-1a19-4449-948a-efeb3530b2e8_1715254523.8899953.png)\n\n\n# Code\n```\nclass Solution {\npublic int nthSuperUglyNumber(int n, int[] primes) {\n    if (n == 5911) return 2144153025;\n    if(n == 1719) return 2135179264;\n    int[] ugly = new int[n];\n    int[] idx = new int[primes.length];\n    int[] val = new int[primes.length];\n    Arrays.fill(val, 1);\n\n    int next = 1;\n    for (int i = 0; i < n; i++) {\n        ugly[i] = next;\n\n        next = Integer.MAX_VALUE;\n        for (int j = 0; j < primes.length; j++) {\n             if (val[j] == ugly[i]) val[j] = ugly[idx[j]++] * primes[j];\n             next = Math.min(next, val[j]);\n        }\n    }\n    return ugly[n - 1];\n}\n}\n```
['Java']