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的更多相关文章

  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. 第十五篇 JS 移入移出事件 模拟一个二级菜单

    JS 移入移出事件 模拟一个二级菜单   老师演示一个特别简单二级菜单,同学们除了学习JS,还要注意它的元素和CSS样式. 这节课介绍的是JS鼠标移入.移出事件:onmouseover是移入事件,on ...

  2. uploadify 上传文件插件

    今天在项目中要用到文件上传功能时,想借助Jquery方式来实现,于是想到用uploadify插件来实现.不经意间在网上看到了一遍关于这个插件的用法,写的很好.在这里就分享给大家,希望对大家有帮助.以下 ...

  3. react + antd Form表单校验

    非空限制 {getFieldDecorator('name', { rules: [{ required: true, message: '名称不能为空', }],})( <Input plac ...

  4. MySQL 下载与安装

    从MySQL官网下载安装文件,我的电脑是window10 64位的,下载社区版本,选择mysql community server,再下载64位的. 官网链接:https://www.mysql.co ...

  5. Zookeeper启动失败,报错 can not open chanel to 2

    zookeeper 3.4.8 安装在 7 台不同的虚拟机上,配置文件如下: tickTime= initLimit= syncLimit= dataDir=/var/zookeeper client ...

  6. 前端面试题-CSS Hack

    一.CSS Hack的概念 由于不同厂商的流览器或某浏览器的不同版本(如IE,Firefox/Safari/Opera/Chrome等),对CSS的支持.解析不一样,导致在不同浏览器的环境中呈现出不一 ...

  7. 命令方式 搭建 (简易)Maven项目

    原料:1.配好的Maven环境变量    2.c m d命令 win  + r  输入 cmd 切换到此项目所要存在的位置 使用命令创建文件夹 切换 到 maven_demo中  输入 cd mave ...

  8. 开始PHP,常量/变量与内存间的关系--传值

    一.常见的PHP代码嵌入式方式,与html结合 要注意:文件名后缀必须形如xxx.php否则html将无法解析 二.php脱离html代码独立工作,没有其他代码 不需要借助Apache工作,只需要ph ...

  9. Python 正则表达式Ⅲ

    re.match与re.search的区别 re.match只匹配字符串的开始,如果字符串开始https://www.xuanhe.net/不符合正则表达式,则匹配失败,函数返回None:而re.se ...

  10. static后期静态绑定

    先说一下__CLASS__,get_class() ,  get_called_class() 区别: __CLASS__获取当前的类名, get_class()与上面一样,都是获取当前的类名, ge ...