Python Simple Solution


  • 0
    D
    from random import choice
    class Solution(object):
    
        def __init__(self, nums):
            """
            
            :type nums: List[int]
            :type numsSize: int
            """
            self.data = nums
    
        def pick(self, target):
            """
            :type target: int
            :rtype: int
            """
            ra = filter(lambda i: self.data[i] ==  target, range(len(self.data)))
            return choice(ra)
            
    
    
    # Your Solution object will be instantiated and called as such:
    # obj = Solution(nums)
    # param_1 = obj.pick(target)

Log in to reply
 

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