public class Solution {
private int[] nums;
private Random random; public Solution(int[] nums)
{
this.nums = nums;
random = new Random();
} /** Resets the array to its original configuration and return it. */
public int[] Reset()
{
return nums;
} /** Returns a random shuffling of the array. */
public int[] Shuffle()
{
if (nums == null)
{
return null;
}
int[] a = (int[])nums.Clone();
for (int j = ; j < a.Length; j++)
{
int i = random.Next(j + );
Swap(a, i, j);
}
return a;
} private void Swap(int[] a, int i, int j)
{
int t = a[i];
a[i] = a[j];
a[j] = t;
}
} /**
* Your Solution object will be instantiated and called as such:
* Solution obj = new Solution(nums);
* int[] param_1 = obj.Reset();
* int[] param_2 = obj.Shuffle();
*/

https://leetcode.com/problems/shuffle-an-array/#/description

leetcode384的更多相关文章

  1. [Swift]LeetCode384. 打乱数组 | Shuffle an Array

    Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...

随机推荐

  1. Chrome 插件下载

    这里推荐几个下载chrome扩展的网站 http://www.cnplugins.com/index.html 分类全,没有搜索 http://www.chromein.com/ 有搜索,推荐使用 h ...

  2. lx 与cd 的计算方法

    Candela to lux calculation with distance in meters The illuminance Ev in lux (lx) is equal to the lu ...

  3. 浅谈Eclipse调用Tomcat服务的原理

    浅谈Eclipse调用Tomcat服务的原理 转:http://www.thinksaas.cn/group/topic/341645/ 转:http://www.173it.cn/Html/?581 ...

  4. Jmeter-Threads(Users)

    setUp Thread Group---测试开始前的准备操作,每次测试前都会执行 A special type of ThreadGroup that can be utilized to perf ...

  5. ueditor编辑器【实际项目使用】

    [页面效果] [代码] 说明: ueditor插件的公共代码: 如果是一个可以放在对应模块的js代码中   如果有多个就要提到全局的高度(即提到公共部分) <script type=" ...

  6. BZOJ4602 Sdoi2016 齿轮 【带权并查集】*

    BZOJ4602 Sdoi2016 齿轮 Description 现有一个传动系统,包含了N个组合齿轮和M个链条.每一个链条连接了两个组合齿轮u和v,并提供了一个传动比x : y.即如果只考虑这两个组 ...

  7. Quartz 2D编程指南(5) - 变换(Transforms)

    Quartz 2D 绘制模型定义了两种独立的坐标空间:用户空间(用于表现文档页)和设备空间(用于表现设备的本地分辨率).用户坐标空间用浮点数表示坐标,与设备空间的像素分辨率没有关系.当我们需要一个点或 ...

  8. FastAdmin 中使用 Oder by if 强行将某一类放到前面

    FastAdmin 中使用 Oder by if 强行将某一类放到前面 问题来源社区问题 1,查了一些资料2,做了测试. 如下表,我想把 snake 单独放到开始. 可以使用以下查询语句(默认为 AS ...

  9. SSH远程登录CentOS服务器

    1.把ssh默认远程连接端口修改为2200编辑防火墙配置:vi /etc/sysconfig/iptables防火墙增加新端口2222 -A INPUT -m state --state NEW -m ...

  10. RK3288 查看时钟树

    主控端可以通过指令查看时钟树,enable_cnt为1,表示时钟已使能. # cat d/clk/clk_summary cat d/clk/clk_summary clock enable_cnt ...