思路:用一个字典统计出每个数字出现的次数,然后遍历字典,找到只出现一次的
# -*- 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
原文地址:https://www.cnblogs.com/dolisun/p/11331294.html
时间: 2024-10-10 07:30:19