-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
39 lines (33 loc) · 1 KB
/
solution.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
class MyHashMap(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.buckets = [None] * 1000000
def put(self, key, value):
"""
value will always be positive.
:type key: int
:type value: int
:rtype: void
"""
self.buckets[key - 1] = value
def get(self, key):
"""
Returns the value to which the specified key is mapped, or -1 if this map contains no mapping for the key
:type key: int
:rtype: int
"""
return self.buckets[key - 1] if self.buckets[key - 1] != None else -1
def remove(self, key):
"""
Removes the mapping of the specified value key if this map contains a mapping for the key
:type key: int
:rtype: void
"""
self.buckets[key - 1] = None
# Your MyHashMap object will be instantiated and called as such:
# obj = MyHashMap()
# obj.put(key,value)
# param_2 = obj.get(key)
# obj.remove(key)