link solu1:

class Solution:
    # time O(N) space O(N)
    def singleNumber(self, nums: List[int]) -> int:
        d = collections.defaultdict()
        for i in nums:
            if not d.get(i):
                d[i] = 1
            else:
                d[i] += 1
                
        for each in d.keys():
            if d[each] == 1:
                return each   

class Solution:
    # time(N) spaceO(1)
    # main idea :  a XOR 0 = a ;   a XOR a = 0;  a XOR b XOR a = (a XOR a) XOR b = 0 XOR b = b
    def singleNumber(self, nums: List[int]) -> int:
        a = 0
        for num in nums:
            a ^= num
        return a