leetcode384
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的更多相关文章
- [Swift]LeetCode384. 打乱数组 | Shuffle an Array
Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] n ...
随机推荐
- hexo的环境搭建
今天开始折腾下hexo,安装起来还是有点坑,简单记录下,会不断更新. 网上安装的文章多不胜数,当然首先还是得去看看官方的文档. 按照官方的文档,不知大家是否顺利,本人搭建环境的时候并不顺利. 明确要安 ...
- js实现图片上传
//上传图片 function uploadImg(){ //loading $("#loading").ajaxStart(function() { $(this).show() ...
- 实现一个 WPF 版本的 ConnectedAnimation
Windows 10 的创造者更新为开发者们带来了 Connected Animation 连接动画,这也是 Fluent Design System 的一部分.它的视觉引导性很强,用户能够在它的帮助 ...
- spec.template.spec.initContainers[1].securityContext.privileged: Forbidden: disallowed by policy 问题解决
主要是执行系统特权应用解决方法: api server controller-manager 加上 --allow-privileged=true 即可 之后重启服务
- jekyll 安装使用
1. 安装 条件: ruby gem 注意版本,同时建议使用国内的镜像 gem install jekyll bundler 2. 创建网站 jekyll new my-awesome ...
- 【转】Linux 静态库与共享库的使用
原文网址:http://blog.csdn.net/heyabo/article/details/11688517 申明: 正如题如示,本篇讲的是Linux下是静态库与共享库,而Window下的动态链 ...
- 洛谷3195(HNOI2008)玩具装箱
题目:https://www.luogu.org/problemnew/show/P3195 自己做斜率优化的第一道题. 推成斜率优化的样子很重要. 斜率优化的样子就是从 j 中求 i 的话,关系式里 ...
- Openfire源码使用Install4j打包
https://www.ej-technologies.com/download/install4j/files 下载并安装install4jhttps://www.ej-technologies.c ...
- Web API 路由访问设置
前段时间一直致力于MVC webapi 技术的研究,中途也遇到过好多阻碍,特别是api路由的设置和URL的访问形式,所以针对这个问题,特意做出了记录,以供日后有同样困惑的大虾们借鉴: 在Mvc WEB ...
- java代码------------条件运算符 ?:
总结: package com.sads; //?: //这个运算符是条件运算符 //条件式?值:值 public class Sd { public static void main(String[ ...