FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

leetcode · didi0613/leetcode-javascript@204f3fc · GitHub

Commit 204f3fc

Browse files
committed
leetcode
1 parent 9e72ee6 commit 204f3fc

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎super-ugly-number.js‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number} n
3+
* @param {number[]} primes
4+
* @return {number}
5+
*/
6+
var nthSuperUglyNumber = function (n, primes) {
7+
var count = new Array(primes.length).fill(0);
8+
var res = new Array(n);
9+
res[0] = 1;
10+
11+
for (var i = 1; i < n; i++) {
12+
var min = Number.MAX_VALUE;
13+
for (var j = 0; j < primes.length; j++) {
14+
min = Math.min(min, primes[j] * res[count[j]]);
15+
}
16+
res[i] = min;
17+
18+
for (var j = 0; j < count.length; j++) {
19+
if (res[count[j]] * primes[j] === min) {
20+
count[j]++;
21+
}
22+
}
23+
}
24+
return res[n - 1];
25+
};

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL