public ArrayList<ArrayList<Integer>> threeSum_wrong(int[] num) {

    Arrays.sort(num); // O(NlgN)
    ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
    int head = 0;
    int tail = num.length - 1;
    while (head < tail) {
      int twoSum = num[head] + num[tail];
      int diff = 0 - twoSum;
      for (int i = head + 1 ; i < tail ; i++) {
        if (num[i] == diff) {
          ArrayList<Integer> al = new ArrayList<Integer>();
          al.add(num[head]);
          al.add(num[i]);
          al.add(num[tail]);
          result.add(al);
          break;
        }
      }

      if (twoSum >= 0) {
        while (tail >= 1 && num[tail] == num[--tail]) {
          ;
        }
      } else {
        while (head < num.length - 1 && num[head] == num[++head]) {
          ;
        }
      }
    }
    return result;
  }