class Solution(object): def __init__(self, nums): self.nums = nums def pick(self, target): return random.choice([k for k, v in enumerate(self.nums) if v == target])
@WarrenChen I don't think so. It is iterating over the nums again and again to collect indexes whose value equal target. On init, we are just storing the pointer to the actual array.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.