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 ...
随机推荐
- Centos7:配置防火墙
firewalld的基本使用 启动: systemctl start firewalld 关闭:systemctl stop firewalld 查看状态: systemctl status fire ...
- Ubuntu 18.04 LTS 64位Linux搭建Kubernetes 1.15.3并join子节点的完整过程
1.软件准备 1.1.Ubuntu系统安装 https://ubuntu.com/download#download ubuntu系统需要设置用户,root默认为系统的账户不能被用户设置且每一次开机都 ...
- shell条件嵌套(if条件语句)
[注意1]:和Java.PHP等语言不一样,sh的流程控制不可为空,如: 代码如下: <?php if (isset($_GET["q"])) { search(q); } ...
- lwip 内存配置和使用,以及 如何 计算 lwip 使用了多少内存?
/** * 内存配置 * suozhang 2019年9月6日20:25:48 参考 <<LwIP 应用开发实战指南>> 野火 第5章 LwIP 的内存管理 * * 动态内存池 ...
- java将一数组乱序排列
JAVA的Collections类中shuffle方法模拟了“洗牌”动作可以对list列表进行随机排序.如果一定要自己写,算法也很简单:假设数组array长度为n.用标准随机函数rand(n)生成[0 ...
- 使用h5新特性,轻松监听任何App自带返回键
1.前言 如今h5新特性.新标签.新规范等有很多,而且正在不断完善中,各大浏览器商对它们的支持,也是相当给力.作为前端程序员,我觉得我们还是有必要积极关注并勇敢地加以实践.接下来我将和各位分享一个特别 ...
- 兼容系列-IE678的兼容
1. 最简单的CSS Hack 区分 IE6 . IE7 .IE8 css .color{ background-color: #CC00FF; /*所有浏览器都会显示为紫色*/ background ...
- grunt的安装及使用
windows下安装grunt需要先安装ruby和nodejsruby -v 测试ruby是否安装成功node -v 测试nodejs是否安装成功npm -v 测试npm是否安装成功(npm是node ...
- 【JZOJ5180】【NOI2017模拟6.29】呵呵
题目 分析 套上prufer序列, 对于一颗n个节点度数分别为\(d_1.d_2...d_n\)方案数为\(\dfrac{(n-2)!}{(d_1-1)!(d_2-1)!......(d_n-1)!} ...
- 用CSS创建分页的实例
总结介绍如何通过使用 CSS 来创建分页的实例. ㈠简单分页 如果你的网站有很多个页面,你就需要使用分页来为每个页面做导航. 以下实例演示了如何使用 HTML 和 CSS 来创建分页: <!DO ...