Find the Single Number
EasyPractice library · +10 XPbit manipulationxor tricksarrays
Given an array of integers, where every element appears exactly twice except for one element which appears only once, find that single element.
Input
The first line contains a single integer N, the number of elements in the array. The second line contains N space-separated integers.
Output
Print the single element that appears only once.
Constraints
1 <= N <= 1000 -10^9 <= A[i] <= 10^9
Time limit 1 s (native code; slower languages get more)Memory 256 MB12 hidden tests
Example 1
Input
5 1 2 3 2 1
Output
3
1 appears twice, 2 appears twice, 3 appears once.
Example 2
Input
3 7 8 7
Output
8
7 appears twice, 8 appears once.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
Example 1 input
5 1 2 3 2 1
Example 2 input
3 7 8 7