剑指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
        
    for s in nums:
        ret.append([s,hashes[s]])
        
    return ret


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

 

posted @ 2018-10-29 10:11  findtruth123  阅读(161)  评论(0编辑  收藏  举报