Check out the resources on the page's right side to learn more about bit manipulation. The video tutorial is by Gayle Laakmann McDowell, author of the best-selling interview book Cracking the Coding Interview.
Consider an array of integers, , where all but one of the integers occur in pairs. In other words, every element in occurs exactly twice except for one unique element.
Given , find and print the unique element.
The first line contains a single integer, , denoting the number of integers in the array.
The second line contains space-separated integers describing the respective values in .
It is guaranteed that is an odd number.
, where .
Print the unique number that occurs only once in on a new line.
Sample Input 0
Sample Output 0
The array only contains a single , so we print as our answer.
Sample Input 1
1 1 2
Sample Output 1
We have two 's and one . We print , because that's the only unique element in the array.
Sample Input 2
0 0 1 2 1
Sample Output 2
We have two 's, two 's, and one . We print , because that's the only unique element in the array.