日期:2014-05-19  浏览次数:20645 次

3条语句搞定一亿数据获取前100个最大值
最近我看到论坛有一个贴子“3秒搞定!~~ 一亿数据获取前1000个最大值”很热,我3条语句搞定:
Java code
        Random rand = new Random();
        PriorityQueue<Integer> P = new PriorityQueue<Integer>();
        for(int i = 0,num = rand.nextInt(); (i < 100 && P.add(num)) || (i < 100000000 && (P.peek() < num && P.add(num) && P.remove() != null || 1==1)); i++,num = rand.nextInt());
        //System.out.println(P);



------解决方案--------------------
很强大的