mycode

  1. class Solution(object):
  2.  
  3. def __init__(self, nums):
  4. """
  5. :type nums: List[int]
  6. """
  7. self.res = nums[:]
  8. self.shu = nums[:]
  9.  
  10. def reset(self):
  11. """
  12. Resets the array to its original configuration and return it.
  13. :rtype: List[int]
  14. """
  15. return self.res
  16.  
  17. def shuffle(self):
  18. """
  19. Returns a random shuffling of the array.
  20. :rtype: List[int]
  21. """
  22. import random
  23. self.shu = random.sample(self.res, len((self.res)))
  24. return self.shu
  25.  
  26. # Your Solution object will be instantiated and called as such:
  27. # obj = Solution(nums)
  28. # param_1 = obj.reset()
  29. # param_2 = obj.shuffle()

random.shuffle功能

  1. import random
  2. class Solution(object):
  3.  
  4. def __init__(self, nums):
  5. self.nums = nums
  6. def reset(self):
  7. return self.nums
  8. def shuffle(self):
  9. new_nums = self.nums[:]
  10. random.shuffle(new_nums)
  11. return new_nums

leetcode-easy-design-384 Shuffle an Array的更多相关文章

  1. leetcode 384. Shuffle an Array

    384. Shuffle an Array c++ random函数:https://www.jb51.net/article/124108.htm rand()不需要参数,它会返回一个从0到最大随机 ...

  2. [LeetCode] 384. Shuffle an Array 数组洗牌

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

  3. 【LeetCode】384. Shuffle an Array 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 库函数 Fisher–Yates 洗牌 水塘抽样 日 ...

  4. Java [Leetcode 384]Shuffle an Array

    题目描述: Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. i ...

  5. 384. Shuffle an Array

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

  6. 384. Shuffle an Array数组洗牌

    [抄题]: Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. i ...

  7. LC 384. Shuffle an Array

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

  8. 384 Shuffle an Array 打乱数组

    打乱一个没有重复元素的数组.示例:// 以数字集合 1, 2 和 3 初始化数组.int[] nums = {1,2,3};Solution solution = new Solution(nums) ...

  9. 384. Shuffle an Array(java,数组全排列,然后随机取)

    题目: Shuffle a set of numbers without duplicates. 分析: 对一组不包含重复元素的数组进行随机重排,reset方法返回最原始的数组,shuffle方法随机 ...

  10. [LeetCode] Shuffle an Array 数组洗牌

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

随机推荐

  1. SSM处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题

    在开发中,前端同事调用后端同事写好的接口,在地址中是有效的,但在项目的ajax中,浏览器会报 "No 'Access-Control-Allow-Origin' header is pres ...

  2. zabbix分布式部署和主机自动发现

    1.分布式部署原理 1.1Zabbix分布式部署的原理 传统的部署架构,是server直接监控所有的主机,全部主机的数据都是有server自己来采集和处理,server端的压力比较大,当监控主机数量很 ...

  3. nfs服务的配置

    nfs服务 nfs简介 Network file system 网络文件系统.NFS server可以看作是一个 file server.它可以让你的pc通过网络将远端的nfs server共享出来的 ...

  4. Go语言标准库之fmt.Print

    Go语言fmt.Printf使用指南 本文整理了Go语言的标准输出流(fmt.Printf)在打印到屏幕时的格式化输出操作. 在这里按照占位符将被替换的变量类型划分,更方便查询和记忆. General ...

  5. vi 纵向模式编辑

    Vim 的纵向编辑模式 vim解读 vi解读 批量删除# 技巧: r 进入修改模式 I 进入行首插入模式 A 进入行尾插入模式 r替换 I前前添加 A后添加 1.多行注释: a. 按下Ctrl + v ...

  6. VSCode配合chrome浏览器调试cocos2d js项目

    1.准备阶段 具备调试功能的VSCode(我的是在win10上,版本是1.17.1) 在VSCode里下载安装Debugger for Chrome扩展插件. 2.具体操作 创建一个cocosjs工程 ...

  7. 为了保护dll这么做吗?

    生成dll时候 附带生成的lib文件

  8. 【洛谷P2147】洞穴勘测

    题目大意:维护 N 个点的无向图,支持动态加边和删边,回答两点的连通性. 题解:线段树分治 + 可撤销并查集 询问可以离线,这是线段树分治的基础. 建立在操作时间轴上的线段树称为线段树分治算法. 本题 ...

  9. 【洛谷P1450】硬币购物

    题目大意:给定 4 种面值的硬币和相应的个数,求购买 S 元商品的方案数是多少. 题解: 考虑没有硬币个数的限制的话,购买 S 元商品的方案数是多少,这个问题可以采用完全背包进行预处理. 再考虑容斥, ...

  10. 兼容系列-IE678的兼容

    1. 最简单的CSS Hack 区分 IE6 . IE7 .IE8 css .color{ background-color: #CC00FF; /*所有浏览器都会显示为紫色*/ background ...