博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetcode mock Shuffle an Array
阅读量:7129 次
发布时间:2019-06-28

本文共 752 字,大约阅读时间需要 2 分钟。

1. shuffle算法:

http://www.cnblogs.com/huaping-audio/archive/2008/09/09/1287985.html

注意:我们一般用的是第二种swap的方法;但是第一种直接选择,然后把最末尾一位填上的方法,也是很好的。只是会需要两倍的空间。

 

2. Random nextInt(bound)参数表示 0-inclusive,bound-exclusive: [0, bound)

 

package com.company;import java.util.LinkedList;import java.util.List;import java.util.Random;public class Main {    private int[] orig;    public Main(int[] nums) {        orig = nums;    }    /** Resets the array to its original configuration and return it. */    public int[] reset() {        return orig;    }    /** Returns a random shuffling of the array. */    public int[] shuffle() {        int[] ret = orig.clone();        Random rand = new Random();        for (int i=0; i

 

转载于:https://www.cnblogs.com/charlesblc/p/5936974.html

你可能感兴趣的文章
2013百度安卓巴士轻应用4城市巡展沙龙,免费报名啦
查看>>
给 TextBlock 加 ToolTip
查看>>
android UI进阶之实现listview的分页加载
查看>>
技术贴 本地代码与svn关联教程 svn upgrade问题解决
查看>>
git 仓库、分支的区别
查看>>
mybatis 3 -枚举
查看>>
如何把光盘制作成ISO镜像文件
查看>>
jquery-仿flash的一个导航栏特效
查看>>
【大型网站技术实践】初级篇:借助Nginx搭建反向代理服务器(转)
查看>>
基于jQuery环形图标菜单旋转切换特效
查看>>
【165】最失败国家排名
查看>>
Delphi 包的设计思想及它与PAS、BPL、DCU、DLL、OXC的关系。
查看>>
教程-Win7极速优化20项
查看>>
设计思想
查看>>
坦克大战
查看>>
Objective-C时间戳转换的转换和时间
查看>>
ubuntu下code::blocks设置运行窗口为gnome命令行
查看>>
《C++ Primer Plus》15.5 类型转换运算符 学习笔记
查看>>
css继承样式怎么控制?用选择器
查看>>
DICOM医学图像窗口变换的加速算法
查看>>