-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesignHashSet.py
More file actions
49 lines (40 loc) · 1.11 KB
/
designHashSet.py
File metadata and controls
49 lines (40 loc) · 1.11 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
class MyHashSet(object):
def __init__(self):
self.capacity= 1000001;
self.set = [None]*self.capacity;
def hash(self, key):
return key % self.capacity;
def add(self, key):
"""
:type key: int
:rtype: None
"""
address = hash(key);
if self.set[address] is None :
self.set[address] = [];
self.set[address]=key;
#else:
# self.set[address].append(key);
def remove(self, key):
"""
:type key: int
:rtype: None
"""
address = hash(key);
if self.set[address] is not None:
#if key in self.set[address]:
self.set[address] = None;
def contains(self, key):
"""
:type key: int
:rtype: bool
"""
address = hash(key);
if self.set[address] is not None:
#if key in self.set[address]:
return True;
# Your MyHashSet object will be instantiated and called as such:
# obj = MyHashSet()
# obj.add(key)
# obj.remove(key)
# param_3 = obj.contains(key)