问题描述: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?
example:[1,2,2,3,3,4,4,5,5]
output:1
想到1个数或同一个数两次还是同一个数。符合本题
代码:
public class Solution {
public int singleNumber(int[] nums) {
int num=nums[0];
for(int x=1;x<nums.length;x++)
num=num^nums[x];
return num;
}
}