How do I get the element that appears once in a double array? Below is what I have tried, and the execution time is unacceptable. This will be ran against very huge arrays. There can only be one unique element.
public static double getUnique(double arr[]) {
double res = 0.0;
for (int i = 0; i < arr.length; i++){
res = arr[i];
int count = 0;
for (int j = 0; j < arr.length; j++){
if (res == arr[j]){
count ++;
}
if(j == arr.length - 1){
if(count == 1){
return res;
}
}
}
}
return res;
}