#C11940. Find the Unique Number
Find the Unique Number
Find the Unique Number
You are given an array of integers where every element appears exactly twice except for one element which appears only once. Your task is to find and print the unique element.
Problem Details:
- The array length is odd, and there is exactly one element that occurs once.
- All other elements appear exactly two times.
- You are required to solve the problem using bitwise operations (specifically, the XOR operator) to achieve optimal performance.
The well known XOR trick is based on the fact that XOR-ing a number with itself cancels out to 0, and XOR is commutative and associative. Thus, XOR-ing all the numbers in the array yields the unique number.
Mathematically, if the array is \(a_1, a_2, \dots, a_n\), then the answer is given by:
[ \text{answer} = a_1 \oplus a_2 \oplus \cdots \oplus a_n, ]
where \(\oplus\) denotes the bitwise XOR operation.
inputFormat
The first line of input contains an odd integer \(n\) which represents the number of elements in the array. The second line contains \(n\) space-separated integers.
outputFormat
Output a single integer representing the element that appears only once in the array.
## sample5
2 3 2 4 4
3
</p>