#K36252. Find the Unique Element
Find the Unique Element
Find the Unique Element
You are given an array of integers of odd length. Every element in the array appears exactly twice except for one element which appears exactly once. Your task is to find and print the element that appears only once.
This problem can be efficiently solved using the bitwise XOR operator. Recall that for any integer a, a ⊕ a = 0
and a ⊕ 0 = a
. By XOR-ing all elements together, the duplicate elements cancel each other out, leaving only the unique element.
Note: The input is provided via stdin and the output should be printed to stdout.
inputFormat
The first line contains an integer n (where n is odd), which denotes the number of elements in the array. The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output the unique integer that appears exactly once in the array.
## sample5
1 2 3 2 1
3