算法编程题思路分享

题目:给定一个整数数组,除某个数外,其他数都出现两次,找到这个唯一数。
要求:线性时间复杂度,不占用额外空间。
考点:异或运算的应用

解题要点:
1: 两个相同的数异或为0
2: 0异或任何数不变
public int singleNumber(int[] A) {
int temp = 0;
for(int i=0;i<A.length;i++){
temp^=A[i];
}
return temp ;
}

猜你喜欢

转载自blog.csdn.net/u011114913/article/details/78959431