标签:style blog class code c color
Given an array of integers, every element appears twice except for one. Find that single one.
因为只有一个数是一个,其余都为2个,故采用一直异或下去就可以求得结果
class Solution {
public:
int singleNumber(int A[], int n) {
for(int i = 0; i < n; i++)
{
if(n == 1)
{
return A[0];
}
if(i == 0)
{
i++;
}
A[0] ^= A[i];
}
return A[0];
}
};[LeetCode]Single Number,布布扣,bubuko.com
标签:style blog class code c color
原文地址:http://blog.csdn.net/jet_yingjia/article/details/25732699