eimhee 发表于 2013-1-27 04:45:12

阿里巴巴笔试题-2个有序集合的交集

题目来自于论坛:http://topic.csdn.net/u/20081012/14/3cc93688-1f7f-4985-806c-3f729c78261b.html

不过我使用的是TreeSet,因为题目要求是集合
<div class="highlighter">
[*]  public static void test2() {
[*]    TreeSet<Integer> a = new TreeSet<Integer>();
[*]    TreeSet<Integer> b = new TreeSet<Integer>();
[*]    Random r = new Random();
[*]    for (int i = 0; i < 30; i++) {
[*]      a.add(r.nextInt(30));
[*]      b.add(r.nextInt(30));
[*]    }
[*]    a.retainAll(b);
[*]    System.out.println(a);
[*]    System.out.println(b);
[*]    System.out.println(a);
[*]  }
页: [1]
查看完整版本: 阿里巴巴笔试题-2个有序集合的交集