#K67497. Find the Unique Element
Find the Unique Element
Find the Unique Element
Given an array of integers in which every element appears exactly twice except for one that appears only once, your task is to find and output the unique element.
You should solve this problem in an optimal way. A hint for an efficient solution is to use bitwise XOR operation: for any integer \(a\), \(a \oplus a = 0\) and \(0 \oplus a = a\). By applying XOR over all elements, the duplicate values cancel out leaving the unique element.
The program must read 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 representing the elements of the array.
outputFormat
Output a single integer which is the unique element present in the array.## sample
1
5
5