阿里巴巴筆試題-2個有序集合的交集

才智咖 人氣:6.63K

(轉載我使用的是TreeSet,因為題目要求是集合
  public static void test2() {
    TreeSet

阿里巴巴筆試題-2個有序集合的交集

a = new TreeSet();
    TreeSetb = new TreeSet();
    Random r = new Random();
    for (int i = 0; i < 30; i++) {
      (Int(30));
      (Int(30));
    }
    inAll(b);
    tln(a);
    tln(b);
    tln(a);
  }
其中的'retainAll是JDK自帶的演算法,我們看一下源程式碼
  public boolean retainAll(Collection