1
var Solution = function (nums) {
2
this.map = nums.reduce((result, num, index) => {
3
const value = result.get(num) ?? [];
4

5
value.push(index);
6
result.set(num, value);
7
return result;
8
}, new Map());
9
};
10

11
Solution.prototype.pick = function (target) {
12
const pick = this.map.get(target);
13
const random = (Math.random() * pick.length) | 0;
14

15
return pick[random];
16
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0