class ListNode:
def __init__(self, key=-1, val=-1, next=None):
self.key = key
self.val = val
self.next = next
class MyHashMap:
def __init__(self):
self.map = [ListNode() for i in range(1000)]
def hashcode(self, key):
return key % len(self.map)
def put(self, key: int, value: int) -> None:
cur = self.map[self.hashcode(key)]
while cur.next:
if cur.next.key == key:
cur.next.val = value
return
cur = cur.next
cur.next = ListNode(key, value)
def get(self, key: int) -> int:
cur = self.map[self.hashcode(key)].next
while cur and cur.key != key:
cur = cur.next
if cur:
return cur.val
return -1
def remove(self, key: int) -> None:
cur = self.map[self.hashcode(key)]
while cur.next and cur.next.key != key:
cur = cur.next
if cur and cur.next:
cur.next = cur.next.next