[40.] wins the Offer only appears once in the array of digital python to achieve

Title Description

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.

# -*- coding:utf-8 -*-
class Solution:
    # 返回[a,b] 其中ab是出现一次的两个数字
    def FindNumsAppearOnce(self, array):
        hashMap = {}
        for i in array:
            if str(i) in hashMap:
                hashMap[str(i)] += 1
            else:
                hashMap[str(i)] = 1
        res = []
        for k in hashMap.keys():
            if hashMap[k] == 1:
                res.append(int(k))
        return res
Published 99 original articles · won praise 6 · views 3953

Guess you like

Origin blog.csdn.net/weixin_42247922/article/details/104021589