Given an array of integers, every element appearstwiceexcept for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Answer:
class Solution(object):
? ? def singleNumber(self, nums):
? ? ? ? result = 0
? ? ? ? for num in nums:
? ? ? ? ? ? result ^= num#異或運(yùn)算
? ? ? ? return result