参考:https://blog.csdn.net/wem603947175/article/details/82117675
这道题很简单,用字典的方法做的,但是我的字典实现超过时间限制。对比如下: (学习(*^▽^*))
# 通过,优于我的字典存取
# class Solution(object):
# def singleNumber(self, nums):
# dict={}
# sum = []
# for num in nums:
# if num in dict:
# dict[num]+=1
# else:
# dict[num]=1
# for key in dict.keys():
# if dict[key]==1:
# sum.append(key)
# return sum
# # 超出时间限制
# rs = []
# dict = {}
# for i in nums:
# if i not in dict.keys():
# dict[i] = 1
# else:
# count = dict[i]
# count += 1
# dict[i] = count
# for key,value in dict.items():
# if value!=2:
# rs.append(key)
# if len(rs)==2:
# return rs
但是参考里的第一种思路不是很懂,记录如下: