# 看了其他语言的解题代码 人生苦短 用我python 😂😂😂😂😂😂
class Solution(object):
def __init__(self, nums):
"""
:type nums: List[int]
"""
self.nums = nums
def reset(self):
"""
Resets the array to its original configuration and return it.
:rtype: List[int]
"""
return self.nums
def shuffle(self):
"""
Returns a random shuffling of the array.
:rtype: List[int]
"""
import random
nums = self.nums[:]
random.shuffle(nums)
return nums
# random.sample()不用自定义新的数组
class Solution2(object):
def __init__(self, nums):
"""
:type nums: List[int]
"""
self.nums = nums
def reset(self):
"""
Resets the array to its original configuration and return it.
:rtype: List[int]
"""
return self.nums
def shuffle(self):
"""
Returns a random shuffling of the array.
:rtype: List[int]
"""
import random
return random.sample(self.nums, len(self.nums))
# Your Solution object will be instantiated and called as such:
nums = [1,2,3]
obj = Solution2(nums)
param_1 = obj.reset()
print(nums)
param_2 = obj.shuffle()
print(param_2)
网友评论