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. 【javascript 】组合式继承

    开发人员采用的js的继承结构 function inheritPrototype(subType, superType) { var prototype = object(superType.prot ...

  2. Unity的 NavMeshObstacle 的使用详解

            这个组件放在场景中的导航网格上,可以阻挡NavMeshAgent的移动.以Unity4.3.4为例.         NavMeshObstacle 分为两种模式,一种是普通模式,通过 ...

  3. skywalking探针tomcat8.0.28报错解决

    在部署skywalking agent的时候遇到一个异常 环境如下: tomcat8.0.28 catalina.out 日志报如下错误 30-Apr-2019 10:25:57.664 INFO [ ...

  4. ssm框架实现图片上传显示并保存地址到数据库

    本案例是通过springmvc+spring+mybatis框架以商品上传为例,实现的图片上传功能,并把图片的地址保存到数据库并在前台显示上传的图片. 本项目是使用maven搭建的项目,首先看下项目结 ...

  5. Codeforces 28C Bath Queue 【计数类DP】*

    Codeforces 28C Bath Queue LINK 简要题意:有 n 个人等概率随机进入 m 个房间,一个房间可以有多个人,第 i 个房间有 ai 个水龙头,在一个房间的人要去排队装水,他们 ...

  6. 《DSP using MATLAB》示例Example 8.6

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  7. python之json扩展

    #!/usr/bin/env python # -*- coding: utf8 -*- # __Author: "Skiler Hao" # date: 2017/4/9 15: ...

  8. BZOJ4145 [AMPPZ2014]The Prices

    题意 你要购买m种物品各一件,一共有n家商店,你到第i家商店的路费为d[i],在第i家商店购买第j种物品的费用为c[i][j],求最小总费用. \(n \leq 100,m \leq 16\) 分析 ...

  9. MySQL中地理位置数据扩展geometry的使用心得

    最近学习了些MySQL geometry数据存储和计算,在这里记录下. 1. 环境 geometry推荐在5.6版本以上使用,尽管大部分功能在5.5已经可用,除了距离计算函数st_distance等新 ...

  10. uwsgi配置理解

    最近使用uwsgi 部署了flask应用,出现了不少问题,仔细查阅了一下资料以及翻看了官方文档,就对自己了解到的做个总结~~ 一.http/http-socket/socketuwsgi开头当然少不了 ...