其他分享
首页 > 其他分享> > single.py

single.py

作者:互联网

'''
样例
样例 1:

输入:[1,1,2,2,3,4,4]
输出:3
解释:
仅3出现一次
样例 2:

输入:[0,0,1]
输出:1
解释:
仅1出现一次
'''


def singleNumber(A):
    d = {}
    for i in A:
        if d.get(i, -1) == -1:
            d[i] = 1
        else:
            d[i] += 1

    for i, j in d.items():
        if j == 1:
            return i

if __name__ == '__main__':
    print(singleNumber([1,1,2,2,3,4,4]))
    print(singleNumber([0,0,1]))

标签:__,输出,py,样例,single,singleNumber,print,输入
来源: https://blog.csdn.net/defending/article/details/90317135