Dec 30, 2008

Range is from 1~N and we have n+1 numbers, so we must have one duplicate in the range 1~N

Range is from 1~N and we have n+1 numbers, so we must have one duplicate in the range 1~N

int f(int* a, int N)
{
int dup=0;
for(int i=1;i<=N;i++)
{
dup=(dup) xor (i) xor (a[i]);
}
//dup=dup xor a[n+1]
return dup;
}

No comments:

Post a Comment