forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_313.java
29 lines (22 loc) · 774 Bytes
/
_313.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fishercoder.solutions;
public class _313 {
public static class Solution1 {
public int nthSuperUglyNumber(int n, int[] primes) {
int[] ret = new int[n];
ret[0] = 1;
int[] indexes = new int[primes.length];
for (int i = 1; i < n; i++) {
ret[i] = Integer.MAX_VALUE;
for (int j = 0; j < primes.length; j++) {
ret[i] = Math.min(ret[i], primes[j] * ret[indexes[j]]);
}
for (int j = 0; j < indexes.length; j++) {
if (ret[i] == primes[j] * ret[indexes[j]]) {
indexes[j]++;
}
}
}
return ret[n - 1];
}
}
}