706. Design HashMap
https://leetcode.com/problems/design-hashmap/
Python
Remainder Mapping into Array
- Time: Put,Get,Remove are all O(1)
- Space: O(10^6)
class MyHashMap:
def __init__(self):
self.memory = [None]*(10**6)
def put(self, key: int, value: int) -> None:
self.memory[key % (10**6)] = value
def get(self, key: int) -> int:
result = self.memory[key % (10**6)]
return result if result is not None else -1
def remove(self, key: int) -> None:
self.memory[key % (10**6)] = None