forked from AnasImloul/Leetcode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDesign HashMap.py
More file actions
26 lines (22 loc) · 729 Bytes
/
Design HashMap.py
File metadata and controls
26 lines (22 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Runtime: 2037 ms (Top 14.35%) | Memory: 17.2 MB (Top 80.82%)
class MyHashMap:
def __init__(self):
self.keys = []
self.values = []
def put(self, key: int, value: int) -> None:
if key not in self.keys:
self.keys.append(key)
self.values.append(value)
else:
idx = self.keys.index(key)
self.values[idx] = value
def get(self, key: int) -> int:
if key not in self.keys:
return -1
idx = self.keys.index(key)
return self.values[idx]
def remove(self, key: int) -> None:
if key in self.keys:
idx = self.keys.index(key)
del self.keys[idx]
del self.values[idx]