[LinkedIn] Find all triangles in an array
From Here Changed it a little
public ArrayList<ArrayList<Integer>> valid2(int[] A) {
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>();
Arrays.sort(A);
for (int i = 0; i < A.length; ++i) {
for (int j = i; j < A.length; ++j) {
for (int l = j; l < A.length && A[i] + A[j] > A[l]; l++) {
ArrayList<Integer> tmp = new ArrayList<Integer>();
tmp.add(A[i]);
tmp.add(A[j]);
tmp.add(A[l]);
result.add(tmp);
}
}
}
return result;
}