思路:建立哈希表
Python:
class Solution: def singleNumber(self, nums: List[int]) -> int: adict={} for i in range(len(nums)): if nums[i] not in adict: adict[nums[i]]=1 else: adict[nums[i]]+=1 for key in adict: if adict[key]==1: return key
class Solution: def singleNumber(self, nums: List[int]) -> int: adict={} for i in range(len(nums)): if nums[i] not in adict: adict[nums[i]]=1 else: adict[nums[i]]+=1 for key in adict: if adict[key]==1: return key