Problem:
Given 2*n + 1 numbers, every numbers occurs twice except one, find it.
Have you met this question in a real interview? Yes
Example
Given [1,2,2,1,3,4,3], return 4
Challenge
One-pass, constant extra space.
Solution:
As we know, each two same integer after xor operation will lead to 0x00000000.
And if x is an integer, 0x00000000 ^ x = x.
So we can take the adantage of xor property to solve this problem.
1 | /************************************************************************* |