class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
return sum(set(nums))*2-sum(nums)
通过异或(XOR)的方式求解
class Solution:
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
ans=0
for num in nums:
ans^=num
return ans