my solution


  • 0
    J
    class Solution(object):
        def __init__(self, nums):
            self.next = 1
            self.nums = nums
            self.bnums = []
            for x in self.nums:
                self.bnums.append(x)
    
        def rand(self, m):
            self.next = (self.next * 109 + 1021) % 32768
            return self.next % m
    
        def reset(self):
            return self.nums
    
        def shuffle(self):
            for i in range(len(self.bnums)-1, -1, -1):
                j = self.rand(i+1)
                self.bnums[i], self.bnums[j] = self.bnums[j], self.bnums[i]
            return self.bnums
    

Log in to reply
 

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