[LeetCode]136. Single Number

Given an array of integers, every element appears twice except for one. Find that single one.

找出一个数组中唯一一个只出现了一次的数,其余的都出现了两次

 1 class Solution(object):
 2     def singleNumber(self, nums):
 3         """
 4         :type nums: List[int]
 5         :rtype: int
 6         """
 7         if len(nums)==1:
 8             return nums[0]
 9         num = 0
10         for i in nums:
11             num ^= i
12         return num
原文地址:https://www.cnblogs.com/fcyworld/p/6502670.html