Criteria for solving the problem: Reduce the complexity to linear. I can use Arrays with a comparable collection type . Duplicates must be allowed.
My concern: My code snippet (methods for getting common elements (strings)):
public static ArrayList<Comparable> findCommonElements(Comparable items[][]) {
int i, j=0;
int rows = items.length;
ArrayList common = new ArrayList();
int []x = new int[rows];
for(i=0; i<items.length; i++) {
Comparable value = collections[0][x[0]];
for(j=0;j<items[i].length; j++) {
if(items[i][j].compareTo(value)==0) {
common.add(value);
x[0]++;
}
}
}
return common;
}
My conclusion:
[a, c, d]
The correct conclusion:
[a, s, d, e, d]
source
share