剑指offer python版 数组中出现次数超过一半的数字

def aa(nums):
    if not nums:
        return False
    hashes={}
    ret=[]
    for s in nums:
        hashes[s]=hashes[s]+1 if hashes.get(s) else 1
        if hashes[s] >len(nums)/2:
            ret.append(s)
            
    return list(set(ret))


print(aa([1,2,3,2,2,2,2,2,3,2,3,3,4]))
            

 

posted @ 2018-10-26 13:37  findtruth123  阅读(230)  评论(0编辑  收藏  举报