reference:
http://www.geeksforgeeks.org/find-the-number-occurring-odd-number-of-times/
Problem Definition:
Given an array of positive integers. All numbers occur even number of times except one number which occurs odd number of times. Find the number in O(n) time & constant space.
Solution:
Do bitwise XOR of all the elements. Finally we get the number which has odd occurrences.
Code:
int getOddOccurrence(int ar[], int ar_size)
{
int i;
int res = 0;
for (i=0; i < ar_size; i++)
res = res ^ ar[i];
return res;
}