leetcode-python-打乱数组

简单

注意origin不能保持一样,否则random的时候同时修改原始属性

import random
class Solution:

    def __init__(self, nums: List[int]):
        self.origin = nums[:]
        self.temp = nums
    def reset(self) -> List[int]:
        """
        Resets the array to its original configuration and return it.
        """
        return self.origin


    def shuffle(self) -> List[int]:
        """
        Returns a random shuffling of the array.
        """
        random.shuffle(self.temp)
        return self.temp



# Your Solution object will be instantiated and called as such:
# obj = Solution(nums)
# param_1 = obj.reset()
# param_2 = obj.shuffle()

 

posted @ 2021-06-08 15:57  泊鸽  阅读(69)  评论(0)    收藏  举报