数组中只出现一次的数字-python
思路:用一个字典统计出每个数字出现的次数,然后遍历字典,找到只出现一次的
# -*- coding:utf-8 -*-
class Solution:
# 返回[a,b] 其中ab是出现一次的两个数字
def FindNumsAppearOnce(self, array):
# write code here
dic = {}
for i in array:
if i in dic:
dic[i] += 1
else:
dic[i] = 1
res = []
for i in dic:
if dic[i] == 1:
res.append(i)
return res