剑指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]))
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]))