Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
Example 1:
Input: [2,2,1]
Output: 1
Example 2:
Input: [4,1,2,1,2]
Output: 4
题目意思很简单,看到出现一次这个关键字,应该就可以想到异或这个解法。
其他解法,如使用哈希表速度远远不如异或快。
Python解法如下:
class Solution:
def singleNumber(self, nums