[size=large][b]题目描述:Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? [/b][/size]
[size=large][b]1 自己的代码[/b][/size]
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? [/b][/size]
[size=large][b]1 自己的代码[/b][/size]
import java.util.Arrays;
public class SingleNumber {
public int singleNumber(int[] A) {
Arrays.sort(A);
int result = A[0];
for(int i = 0; i < A.length; i = i + 2){
if(i == A.length - 1){
result = A[i];
break;
}
if(A[i] == A[i+1]) continue;
else{
result = A[i];
break;
}
}
return result;
}
}