Skip to content

Commit 196506e

Browse files
committed
2020-05-25
1 parent 2f6efaf commit 196506e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution(object):
2+
3+
def __init__(self, nums):
4+
"""
5+
:type nums: List[int]
6+
"""
7+
from collections import defaultdict
8+
self.dic = defaultdict(list)
9+
for i, num in enumerate(nums):
10+
self.dic[num].append(i)
11+
12+
def pick(self, target):
13+
"""
14+
:type target: int
15+
:rtype: int
16+
"""
17+
return random.choice(self.dic[target])
18+
19+
20+
# Your Solution object will be instantiated and called as such:
21+
# obj = Solution(nums)
22+
# param_1 = obj.pick(target)

0 commit comments

Comments
 (0)