'''
今天的题目是设计一个哈希表
'''classMyHashMap:def__init__(self):"""
Initialize your data structure here.
"""
self.hash_buckets =1001
self.hash_table =[[]for _ inrange(1001)]defhash(self, key):return key % self.hash_buckets
defput(self, key:int, value:int)->None:"""
value will always be non-negative.
"""
hashkey = self.hash(key)for i in self.hash_table[hashkey]:if i[0]== key:
i[1]= value
return
self.hash_table[hashkey].append([key, value])defget(self, key:int)->int:"""
Returns the value to which the specified key is mapped,
or -1 if this map contains no mapping for the key
"""
hashkey = self.hash(key)for i in self.hash_table[hashkey]:if i[0]== key:return i[1]return-1defremove(self, key:int)->None:"""
Removes the mapping of the specified value key if this map
contains a mapping for the key
"""
hashkey = self.hash(key)for i in self.hash_table[hashkey]:if i[0]== key:
self.hash_table[hashkey].remove(i)