[40]는 제안 만 달성 디지털 파이썬 배열 한번 나타나는 승

제목 설명

두 숫자의 정수 배열뿐만 아니라, 다른 숫자가 두번 나타난다. 이 두 수치에만 나타납니다 찾을 수있는 프로그램을 작성하시기 바랍니다.

# -*- 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
게시 99 개 원래 기사 · 원 찬양 6 · 전망 3953

추천

출처blog.csdn.net/weixin_42247922/article/details/104021589