hashMap = collections.defaultdict(int)
for i in range(5):
    hashMap[i] += 1

   

from collections import Counter
hashmap = Counter()

当获得hashmap中的值的时候,只能用hashmap.get()来实现

但是下面这个字典,可以直接用hashtable[一个数值]取得该数值的数组索引

 hashtable = dict()
        for i, num in enumerate(nums):
            if target - num in hashtable:
                return [hashtable[target - num], i]
            hashtable[nums[i]] = i
        return []


posted on 2021-09-20 22:48  little_power  阅读(299)  评论(0)    收藏  举报