1
/**
2
* @param {number} n
3
* @param {number[]} blacklist
4
*/
5
var Solution = function (n, blacklist) {
6
this.space = n - blacklist.length;
7
this.map = {};
8

9
blacklist.forEach((b, i) => {
10
const next = this.space + i;
11

12
const head = this.map[b] === undefined ? b : this.map[b];
13
const tail = this.map[next] === undefined ? next : this.map[next];
14

15
this.map[head] = tail;
16
this.map[tail] = head;
17
});
18
};
19

20
/**
21
* @return {number}
22
*/
23
Solution.prototype.pick = function () {
24
const result = Math.floor(Math.random() * this.space);
25
return this.map[result] || result;
26
};
27

28
/**
29
* Your Solution object will be instantiated and called as such:
30
* var obj = new Solution(n, blacklist)
31
* var param_1 = obj.pick()
32
*/

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0