剑指offer-数组中只出现一次的数字-数组-python

题目描述

一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。
 
# -*- coding:utf-8 -*-
class Solution:
    # 返回[a,b] 其中ab是出现一次的两个数字
    def FindNumsAppearOnce(self, array):
        hash = {}
        res = []
        for i in array:
            if str(i) in hash:
                hash[str(i)]+=1
            else:
                hash[str(i)] = 1
        for k in hash.keys():
            if hash[k] ==1:
                res.append(k)
        return res

print(Solution().FindNumsAppearOnce([2,4,3,6,3,2,5,5]))

 

posted @ 2019-12-19 11:09  ayew  阅读(195)  评论(0编辑  收藏  举报