首页 > 编程语言 > 详细

leetcode-python-打乱数组

时间:2021-06-08 20:25:16      阅读:18      评论:0      收藏:0      [点我收藏+]

简单

注意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()

 

leetcode-python-打乱数组

原文:https://www.cnblogs.com/cbachen/p/14863193.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!