题目
Given an array of integers, every element appears twice except for one. Find that single one.
思路
两个相同的数字异或为零
代码
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if nums==None or len(nums)==0:
return None
res = 0
for num in nums:
res ^= num
return res