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]))
上一篇:单例模式


下一篇:Leetcode学习笔记:#627. Swap Salary