#C5602. Find the Single Unique Element
Find the Single Unique Element
Find the Single Unique Element
Given an array of integers where every element appears exactly twice except for one unique element that appears only once, your task is to find and output that unique element.
You should solve this problem using bitwise operations. Note that the XOR operator, denoted as \(\oplus\), has the useful properties:
- \(a \oplus a = 0\)
- \(a \oplus 0 = a\)
Thus, if you compute the XOR of all elements in the array, the result will be the unique element:
\[ result = num_0 \oplus num_1 \oplus \cdots \oplus num_{n-1} \]Note: When the input array contains all identical elements (e.g., [7, 7, 7]), the algorithm will return that element since there is no distinct element; assume such input is also valid.
inputFormat
The input is read from stdin and consists of two lines:
- 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 the unique element to stdout as a single integer.
## sample7
2 1 4 5 2 4 1
5