Python - extremely naive yet accepted solution


  • -1
    A
    class Solution(object):
    
        def __init__(self, nums):
            """
            
            :type nums: List[int]
            :type numsSize: int
            """
            self.nums = nums 
    
        def pick(self, target):
            """
            :type target: int
            :rtype: int
            """
            import random 
            pos = random.randint(0, len(self.nums)-1)
            while self.nums[pos] != target:
                pos = random.randint(0, len(self.nums)-1)
            return pos 
    

Log in to reply
 

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