leetcode-easy-design-384 Shuffle an Array
mycode
- class Solution(object):
- def __init__(self, nums):
- """
- :type nums: List[int]
- """
- self.res = nums[:]
- self.shu = nums[:]
- def reset(self):
- """
- Resets the array to its original configuration and return it.
- :rtype: List[int]
- """
- return self.res
- def shuffle(self):
- """
- Returns a random shuffling of the array.
- :rtype: List[int]
- """
- import random
- self.shu = random.sample(self.res, len((self.res)))
- return self.shu
- # Your Solution object will be instantiated and called as such:
- # obj = Solution(nums)
- # param_1 = obj.reset()
- # param_2 = obj.shuffle()
random.shuffle功能
- import random
- class Solution(object):
- def __init__(self, nums):
- self.nums = nums
- def reset(self):
- return self.nums
- def shuffle(self):
- new_nums = self.nums[:]
- random.shuffle(new_nums)
- return new_nums
leetcode-easy-design-384 Shuffle an Array的更多相关文章
- leetcode 384. Shuffle an Array
384. Shuffle an Array c++ random函数:https://www.jb51.net/article/124108.htm rand()不需要参数,它会返回一个从0到最大随机 ...
- [LeetCode] 384. Shuffle an Array 数组洗牌
Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...
- 【LeetCode】384. Shuffle an Array 解题报告(Python & C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 库函数 Fisher–Yates 洗牌 水塘抽样 日 ...
- Java [Leetcode 384]Shuffle an Array
题目描述: Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. i ...
- 384. Shuffle an Array
Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...
- 384. Shuffle an Array数组洗牌
[抄题]: Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. i ...
- LC 384. Shuffle an Array
Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...
- 384 Shuffle an Array 打乱数组
打乱一个没有重复元素的数组.示例:// 以数字集合 1, 2 和 3 初始化数组.int[] nums = {1,2,3};Solution solution = new Solution(nums) ...
- 384. Shuffle an Array(java,数组全排列,然后随机取)
题目: Shuffle a set of numbers without duplicates. 分析: 对一组不包含重复元素的数组进行随机重排,reset方法返回最原始的数组,shuffle方法随机 ...
- [LeetCode] Shuffle an Array 数组洗牌
Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...
随机推荐
- SSM处理 No 'Access-Control-Allow-Origin' header is present on the requested resource 问题
在开发中,前端同事调用后端同事写好的接口,在地址中是有效的,但在项目的ajax中,浏览器会报 "No 'Access-Control-Allow-Origin' header is pres ...
- zabbix分布式部署和主机自动发现
1.分布式部署原理 1.1Zabbix分布式部署的原理 传统的部署架构,是server直接监控所有的主机,全部主机的数据都是有server自己来采集和处理,server端的压力比较大,当监控主机数量很 ...
- nfs服务的配置
nfs服务 nfs简介 Network file system 网络文件系统.NFS server可以看作是一个 file server.它可以让你的pc通过网络将远端的nfs server共享出来的 ...
- Go语言标准库之fmt.Print
Go语言fmt.Printf使用指南 本文整理了Go语言的标准输出流(fmt.Printf)在打印到屏幕时的格式化输出操作. 在这里按照占位符将被替换的变量类型划分,更方便查询和记忆. General ...
- vi 纵向模式编辑
Vim 的纵向编辑模式 vim解读 vi解读 批量删除# 技巧: r 进入修改模式 I 进入行首插入模式 A 进入行尾插入模式 r替换 I前前添加 A后添加 1.多行注释: a. 按下Ctrl + v ...
- VSCode配合chrome浏览器调试cocos2d js项目
1.准备阶段 具备调试功能的VSCode(我的是在win10上,版本是1.17.1) 在VSCode里下载安装Debugger for Chrome扩展插件. 2.具体操作 创建一个cocosjs工程 ...
- 为了保护dll这么做吗?
生成dll时候 附带生成的lib文件
- 【洛谷P2147】洞穴勘测
题目大意:维护 N 个点的无向图,支持动态加边和删边,回答两点的连通性. 题解:线段树分治 + 可撤销并查集 询问可以离线,这是线段树分治的基础. 建立在操作时间轴上的线段树称为线段树分治算法. 本题 ...
- 【洛谷P1450】硬币购物
题目大意:给定 4 种面值的硬币和相应的个数,求购买 S 元商品的方案数是多少. 题解: 考虑没有硬币个数的限制的话,购买 S 元商品的方案数是多少,这个问题可以采用完全背包进行预处理. 再考虑容斥, ...
- 兼容系列-IE678的兼容
1. 最简单的CSS Hack 区分 IE6 . IE7 .IE8 css .color{ background-color: #CC00FF; /*所有浏览器都会显示为紫色*/ background ...