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?
/**
* 解题思路:
* 利用亦或运算的特点 A^A=0
* 将所有整数作亦或运算,最后剩下的就是single one。
*
*/
public class Solution {
public int singleNumber(int[] A) {
int result = 0;
int len = A.length;
for( int i=0; i<len; i++ ){
result ^= A[i];
}
return result;
}
}