40. The first digital array appear only
problem:
In addition to an array of integers in two numbers, the other numbers appear twice. Please write a program to find these two figures appear only.
solve:
thought:
This question is still counting problems, decisive use of the dictionary policy.
python code:
# -*- coding:utf-8 -*-
class Solution:
# 返回[a,b] 其中ab是出现一次的两个数字
def FindNumsAppearOnce(self, array):
# write code here
if not array:
return 0
dic={}
for x in array:
if(dic.get(x)==None):
dic[x]=1
else:
dic[x]+=1
result=[]
for i in dic:
if(dic[i]==1):
result.append(i)
return result[0],result[1]