Create a hashmap
Create a hashmap as the title is pretty self explanatory. This problem can be found in leetcode at this link .
Following is pretty self explanatory solution.
class myMap: def __init__(self,key,val): self.key = key self.val = val self.next = None class MyHashMap: def getHash(self, key): return key%self.n def __init__(self): self.n = 10000 self.data = [None]*self.n def put(self, key: int, val: int) -> None: pos = self.getHash(key) head = self.data[pos] if head==None: self.data[pos] = myMap(key,val) return while True: if head.key==key: head.val = val return elif not head.next: head.next = myMap(key,val) return head = head.next def get(self, key: int) -> int: pos = self.getHash(key) head = self.data[pos] while True: if head==None: return -1 elif head.key==key: return head.val else: head = head.next def remove(self, key: int) -> None: pos = self.getHash(key) head = self.data[pos] if head==None: return # if the head is the key if head.key==key: self.data[pos] = head.next return head2 = head.next while True: if head2==None: return elif head2.key==key: head.next = head2.next return else: head = head.next head2 = head2.next # Your MyHashMap object will be instantiated and called as such: # obj = MyHashMap() # obj.put(key,value) # param_2 = obj.get(key) # obj.remove(key)