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. python--命令(各个模块的安装)

    python命令行 退出python命令行:exit() 安装pymysql pip install pymysql 安装request pip install requests 1.安装django ...

  2. LInux安装MySQL5.7.24详情

    安装包下载 MySQL 的官网下载地址:http://www.mysql.com/downloads/ 我安装的是5.7版本 第二步: 选择:TAR (mysql-5.7.24-el7-x86_64. ...

  3. thinkphp漏洞集合

    整合了一个集合,方便查询 thinkphp 5.0.22 1.http://192.168.1.1/thinkphp/public/?s=.|think\config/get&name=dat ...

  4. Darknet版YOLO安装与配置

    Darknet配置和安装 1. 安装显卡驱动 首先查看一下自己的电脑需要怎样的驱动,我们可以先到 http://www.nvidia.com/Download/index.aspx 查询下我们需要的是 ...

  5. RT-Thread中的串口DMA分析

    这里分析一下RT-Thread中串口DMA方式的实现,以供做新处理器串口支持时的参考. 背景 在如今的芯片性能和外设强大功能的情况下,串口不实现DMA/中断方式操作,我认为在实际项目中基本是不可接受的 ...

  6. win10 安装ubuntu16.04双系统

    安装了两天的ubuntu系统,很是头疼,发现网上的内容,比较繁杂,因此,写此博客,进行综合整理,总结了安装方法.方便大家安装,减少搜索. 电脑是老师的电脑,配置为: 主板:微星 CPU:英特尔i5 7 ...

  7. A Neural Probabilistic Language Model (2003)论文要点

    论文链接:http://www.jmlr.org/papers/volume3/bengio03a/bengio03a.pdf 解决n-gram语言模型(比如tri-gram以上)的组合爆炸问题,引入 ...

  8. Java Pattern和Matcher字符匹配详解

    http://tool.oschina.net/uploads/apidocs/jquery/regexp.html https://blog.csdn.net/rentian1/article/de ...

  9. mysql之单表条件查询

    create table staff_info( id int primary key auto_increment, name varchar(32) not null, age int(3) un ...

  10. SIM800c收发短信及AT指令

    一.sim800设备安装 淘宝搜索sim800,差不多就是这么个样子 购买之后,安装手机卡,卡的缺口向外插入,会有卡住的感觉,再按一下卡会弹出 安装usb转串口驱动(CH340),设备的指示灯先是快闪 ...