思路:建立字典麻昼,遍歷,時(shí)間復(fù)雜度O(n)
代碼:
class Solution:
# 返回[a,b] 其中ab是出現(xiàn)一次的兩個(gè)數(shù)字
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