If we sort the array, any duplication between the values will be close to each other.
That way we can remove them
int a[] = { 1,9,55,1,8,9,77,2,5,54,7,10,11 };
Arrays.sort(a);
int j = 0;
for (int i = 0; i < a.length - 1; i++) {
if (a[i] != a[i + 1]) {
a[j] = a[i];
j++;
}
}
a[j] = a[a.length - 1];
return a;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…