136. Single Number
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?
1. 利用异或运算;
2. a^b=b^a;
3. a^a=0;
4. 0^a=a;
public class Solution {
public int singleNumber(int[] nums) {
if(nums==null||nums.length<=0)
return Integer.parseInt(null);
int result=0;
for(int i=0;i<nums.length;i++){
result^=nums[i];
}
return result;
}
}