简单
注意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()
原文:https://www.cnblogs.com/cbachen/p/14863193.html