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 ...
随机推荐
- axios+FormData文件上传
axios+FormData文件上传 原理:FormData上传 创建一个FormData对象,将得到的文件流对象放在FormData内,然后使用axios上传 注意: 1.请求头设置 headers ...
- openlayers之点,线,面(以城市,河流,省份为例,分别对应点线面)
kpst._this这里指向初始化的map // 设置标注样式函数 function createStyle(name) { // 河流style var riverStyle = new Style ...
- eclipse导入myeclipse中的项目(如何把Webroot改为WebContent)
1.进入项目目录,找到.project文件,打开. 2.找到…代码段. 3.在第2步的代码段中加入如下标签内容并保存: org.eclipse.wst.common.project.facet.cor ...
- python异步IO编程(二)
python异步IO编程(二) 目录 开门见山 Async IO设计模式 事件循环 asyncio 中的其他顶层函数 开门见山 下面我们用两个简单的例子来让你对异步IO有所了解 import asyn ...
- Windows Electron初探
最近闲来无事,玩玩electron. 1.安装nodejs 下载地址:http://nodejs.cn/download/,下载64位.安装完成后,打开C:\Program Files\nodejs\ ...
- ceph问题汇总
1. [ceph_deploy][ERROR ]RuntimeError: Failed to execute command: yum -y install epel-release 解决方案 进入 ...
- 安装驱动模块ko
1. make install 2. 3.手动加载驱动程序 [root@localhost template]# modprobe usbnet [root@localhost template]# ...
- 关于log4j的配置文件
因为要在spring中添加Mongodb,在网上查阅资料的时候我发现有人在web.xml中添加如下代码: <context-param> <param-name>l ...
- Kendo UI for jQuery使用教程:使用MVVM初始化(一)
[Kendo UI for jQuery最新试用版下载] Kendo UI目前最新提供Kendo UI for jQuery.Kendo UI for Angular.Kendo UI Support ...
- vue iOS上传图片file 出错
前言 用vue 移动端上传图片在低版本的 ios 手机上 图片转换base64 在转换file 文件类型 会报错 并且报错 “Script Error ” 查阅了github 和一些文档发现 可以吧 ...