You are given an odd-length array of integers, in which all of them are the same, except for one single number.
Complete the method which accepts such an array, and returns that single different number.
The input array will always be valid! (odd-length >= 3)
int stray(size_t n, int arr[n]) {
int k=arr[0],i,a;
for( i=1;i<(int)n;i++)
{
if(k!=arr[i])
{
a=arr[i];
break;
}
}
int flag=1;
for(i=1;i<(int)n;i++)
{
if(k==arr[i])
{
flag=0;break;
}
}
if(flag)
return k;
else
return a;
}