The problem:
Given an array of integers, every element appears twice except for one. Find that single one.
int OnlyOnce(const int *a, int len)
{
int x = a[0];
for (int i = 1; i < len; i++ )
{
x ^= a[i];
}
return x;
}
The problem:
Given an array of integers, every element appears twice except for one. Find that single one.
int OnlyOnce(const int *a, int len)
{
int x = a[0];
for (int i = 1; i < len; i++ )
{
x ^= a[i];
}
return x;
}