Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.
For example:
Given nums = [1, 2, 1, 3, 2, 5], return [3, 5].
感觉大家都用异或来做啊,用字典感觉好慢
class Solution(object):
def singleNumber(self, nums):
"""
:type nums: List[int]
:rtype: List[int]
"""
dic = {}
for num in nums:
if num not in dic:
dic[num]=1
else:
del dic[num]
return dic.keys()