#C493. Find the Number with an Odd Occurrence
Find the Number with an Odd Occurrence
Find the Number with an Odd Occurrence
You are given a list of integers. Your task is to find and output the number that appears an odd number of times in the list. It is guaranteed that there is exactly one number with an odd frequency in a non‐empty list, and if the list is empty, you should output None
.
The problem can be formulated as follows. Given an integer \( n \) and a list \( A = [a_1, a_2, \dots, a_n] \), find the unique integer \( x \) such that
\[
\sum_{i=1}^{n} \mathbf{1}_{\{a_i = x\}} \equiv 1 \pmod{2},
\]
where \( \mathbf{1}_{\{a_i = x\}} \) is the indicator function that is 1 if \(a_i=x\) and 0 otherwise. If \( n = 0 \), output None
.
inputFormat
Input Format:
- The first line of input contains a single integer \( n \) denoting the number of elements in the list. \( (0 \le n \le 10^5) \)
- The second line contains \( n \) integers separated by spaces.
If \( n = 0 \), the second line will be absent.
outputFormat
Output Format:
- Output a single line containing the number that appears an odd number of times. If the list is empty, output
None
.
13
20 1 1 2 2 3 3 20 4 20 4 5 5
20