1 line python solution


  • 0
    def __init__(self, nums):
        self.nums = nums
    def pick(self, target):
        return random.choice([i for i,n in enumerate(self.nums) if n==target])
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.