-
Notifications
You must be signed in to change notification settings - Fork 94
/
Lonely Integer.py
47 lines (34 loc) · 971 Bytes
/
Lonely Integer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the number that occurs
only once.
Input Format
The first line of the input contains an integer N indicating number of integers.
The next line contains N space separated integers that form the array A.
Constraints
1 <= N < 100
N % 2 = 1 ( N is an odd number )
0 <= A[i] <= 100, ∀ i ∈ [1, N]
"""
__author__ = 'Danyang'
class Solution(object):
def solve(self, cipher):
"""
main solution function
:param cipher: the cipher
"""
A = cipher
bit = 0
for item in A:
bit ^= item
return bit
if __name__ == "__main__":
import sys
f = open("1.in", "r")
# f = sys.stdin
N = int(f.readline().strip())
# construct cipher
cipher = map(int, f.readline().strip().split(' '))
# solve
s = "%s\n" % (Solution().solve(cipher))
print s,