We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e633388 commit c76684fCopy full SHA for c76684f
1 file changed
nthsuper_ugly
@@ -0,0 +1,19 @@
1
+def nthSuperUglyNumber(n, primes):
2
+ res = [1]
3
+ idexs = [0] * len(primes) # first is the current idex
4
+ for i in range(n - 1):
5
+ next = 10000
6
+ min_j = []
7
+ for j, idex in enumerate(idexs): #3
8
+ nextj = res[idex] * primes[j]
9
+ if nextj < next:
10
+ next = nextj
11
+ min_j = [j]
12
+ elif nextj == next:
13
+ min_j.append(j) # we can get mutiple j if there is a tie
14
+ res.append(next)
15
+ for j in min_j:
16
+ idexs[j] += 1
17
+ return res[-1]
18
+
19
+print(nthSuperUglyNumber(9, [2,3,5]))
0 commit comments