[剑指offer]数组中只出现一次的数【python】

题目要求:一个整型数组里除了两个数字之外,其他的数字都出现了两次。请写程序找出这两个只出现一次的数字。

代码:

# -*- coding:utf-8 -*-
class Solution:
    # 返回[a,b] 其中ab是出现一次的两个数字
    def FindNumsAppearOnce(self, array):
        # write code here
        result = []
        array_set = set(array)
        for i in array_set:
            if array.count(i) == 1:
                result.append(i)
        return result

猜你喜欢

转载自blog.csdn.net/jillian_sea/article/details/80782039
今日推荐