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. Vue中全局过滤器期与局部过滤器期的使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. WebSocket的兼容性

    https://github.com/sockjs/sockjs-client https://socket.io/ https://github.com/gimite/web-socket-js h ...

  3. shell 脚本中的入参获取与判断

    1.获取shell脚本的入参个数: $# 2.获取shell脚本的第n个入参的字符个数/字符串长度(注意这里的n需要替换为具体的数字,如果这个数字超过实际的入参个数,结果为0): ${#n}

  4. python jdbc连接 oracle 数据库

    准备写一个代码生成的小工具自己用,第一步,连接数据库 import jaydebeapi url = 'jdbc:oracle:thin:@192.168.0.13:1521:JGD' user = ...

  5. 2019.9.20使用kali中的metasploi获取windows 的权限

    1 kali 基于debin的数字取证系统,上面集成了很多渗透测试工具,其前身是bt5r3(bractrack) 其中Metasploit是一个综合利用工具,极大提高攻击者渗透效率,使用ruby开发的 ...

  6. Lubuntu 16.04 64位兼容32位程序

    第一步:确认自己系统的架构 dpkg --print-architecture输出:amd64 结果为  amd64 表示系统是64位的 第二步:确认打开了多架构支持功能 dpkg --print-f ...

  7. 009(1)-saltstack之salt-ssh的使用及配置管理LAMP状态的实现

    1 salt-ssh的使用 1. 安装salt-ssh[root@slave1 .ssh]# yum install -y salt-ssh 2. 配置salt-ssh # Sample salt-s ...

  8. js 动态获取高度 设置距离

    var boxs = document.getElementById('m2-head');var Height = boxs.clientHeight||o.offsetHeight;console ...

  9. PowerDesigner 生成SQL Server 2005 注释脚本

    --生成数据表的注释EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=[%R%?[N]]%.q:COMMENT% , @l ...

  10. 杀掉nginx进程

    ps aux | grep nginx kill -INT 进程号(例如:2661)