思路:建立字典,遍历,时间复杂度O(n)
代码:
class Solution:
# 返回[a,b] 其中ab是出现一次的两个数字
def FindNumsAppearOnce(self, array):
# write code here
dict_map = {}
res = []
if not array or len(array)<0:
return res
n = len(array)
for i in range(n):
if array[i] in dict_map.keys():
dict_map[array[i]] +=1
else:
dict_map[array[i]]=1
for key in dict_map.keys():
if dict_map[key]==1:
res.append(key)
return res