1def findDuplicate(A):
2
3 xor = 0
4
5 # take xor of all list elements
6 for i in range(len(A)):
7 xor ^= A[i]
8
9 # take xor of numbers from 1 to `n-1`
10 for i in range(1, len(A)):
11 xor ^= i
12
13 # same elements will cancel each other as a ^ a = 0,
14 # 0 ^ 0 = 0 and a ^ 0 = a
15
16 # `xor` will contain the missing number
17 return xor