forked from keon/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrandomized_set.py
More file actions
40 lines (30 loc) · 805 Bytes
/
randomized_set.py
File metadata and controls
40 lines (30 loc) · 805 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Design a data structure that supports all following operations
in average O(1) time.
insert(val): Inserts an item val to the set if not already present.
remove(val): Removes an item val from the set if present.
get_random: Returns a random element from current set of elements.
Each element must have the same probability of being returned.
"""
class RandomizedSet():
"""
idea:
shit
"""
def __init__(self):
pass
def insert(self, val):
pass
def remove(self, val):
pass
def get_random(self):
pass
if __name__ == "__main__":
rset = RandomizedSet()
rset.insert(1)
rset.insert(2)
rset.insert(3)
rset.remove(2)
print(rset.get_random())
print(rset.get_random())
print(rset.get_random())