您的位置:首页 > 其它

现在有1千万个随机数,随机数的范围在1到1亿之间。现在要求写出一种算法,将1到1亿之间没有在随机数中的数求出来

2016-03-10 16:05 856 查看
package data.BitSet;

import java.io.IOException;
import java.util.Random;

public class Data {

 
 public static void main(String[] args)throws Exception {
  test();
 }
 
 /**
  * 求反交集
  * @throws IOException
  */
 public   static void test() throws IOException {
        int[] randomNums = new int[10000000];
        Random random = new Random();
        for (int i = 0, length = randomNums.length; i < length; i++) {
            randomNums[i] = random.nextInt(10000000);
        }
        long start = System.currentTimeMillis();
        boolean[] bitArray = new boolean[10000000];
        for (int i = 0, length = randomNums.length; i < length; i++) {
            bitArray[randomNums[i]] = true;
        }
        for (int i = 0, length = bitArray.length; i < length; i++) {
            if (bitArray[i]) {
                continue;
            }
             //System.out.println(i);
        }
        long end = System.currentTimeMillis();
        System.out.println("Spend milliseconds: " + (end - start));
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: