经典算法题:只出现一次的数字 我们先来看题目介绍这道题的解法对于一些同学来说应该非常深刻其中一个想法是放 Hash Table 每个出现的数字就放在桶里面每次出现就统计代码如下class Solution(object): def singleNumber(self, nums): :type nums: List[int] :rtype: int hash_table {} for i in nums: try: hash_table.pop(i) except: hash_table[i] 1 return hash_table.popitem()[0]但这样子做的话想法可能就太常规了神奇的做法如下使用 XORclass Solution(object): def singleNumber(self, nums): :type nums: List[int] :rtype: int a 0 for i in nums: a ^ i return a