#K48157. Find the Odd Occurrence
Find the Odd Occurrence
Find the Odd Occurrence
You are given a list of integers in which all elements, except one, appear an even number of times. Your task is to find the element that appears an odd number of times.
The problem can be solved efficiently using the XOR operation. Recall that for any integer a, a ⊕ a = 0 and a ⊕ 0 = a. Thus, by taking the XOR of all numbers in the array, the even-occurring elements cancel each other while the odd-occurring element remains.
Read the input from stdin and write the result to stdout.
inputFormat
The first line contains an integer n
representing the number of elements in the array. The second line contains n
space-separated integers.
outputFormat
Output a single integer — the element that appears an odd number of times.## sample
7
1 2 3 2 3 1 3
3