706. Design HashMap
Python
Method | Time | Space |
---|---|---|
construct | O(1) | O(1) |
add | O(logN) | O(1) |
remove | O(3logN) | O(1) |
contains | O(logN) | O(1) |
Array as HashMap
class MyHashSet:
def __init__(self):
self.data = []
def add(self, key: int) -> None:
if key in self.data:
return
self.data.append(key)
def remove(self, key: int) -> None:
if key not in self.data:
return
self.data.pop(self.data.index(key))
def contains(self, key: int) -> bool:
return key in self.data