-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path706-Design-HashMap.py
More file actions
51 lines (44 loc) · 1.36 KB
/
706-Design-HashMap.py
File metadata and controls
51 lines (44 loc) · 1.36 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
# 706. Design HashMap https://leetcode.com/problems/design-hashmap/
# level: easy
# complexity:
# Design a HashMap without using any built-in hash table libraries.
class MyHashMap(object):
"""
a simple implementation to start with
"""
def __init__(self):
"""
Initialize your data structure here.
"""
self.h = [-1]*1000001 # given all keys and values will be in the range of [0, 1000000].
def put(self, key, value):
"""
value will always be non-negative.
:type key: int
:type value: int
:rtype: None
"""
self.h[key] = 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.h[key]
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: None
"""
self.h[key] = -1
"""
Open hashing approach: TODO
reference https://leetcode.com/problems/design-hashmap/discuss/185347/Hash-with-Chaining-Python
"""
# Your MyHashMap object will be instantiated and called as such:
# obj = MyHashMap()
# obj.put(key,value)
# param_2 = obj.get(key)
# obj.remove(key)