两个相同的数字异或等于1,任意数字异或0保持不变,因此所有数全部异或就能找到那个数。
python:
class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
res = 0
for i in nums:
res = res^i
return res