42 lines
693 B
Python
42 lines
693 B
Python
import random as r
|
|
|
|
def __init__(self):
|
|
randomSet = ()
|
|
|
|
def insert(self, val):
|
|
"""
|
|
:type val: int
|
|
:rtype: bool
|
|
"""
|
|
if val is None:
|
|
return None
|
|
if val not in self:
|
|
self.add(val)
|
|
return True
|
|
return False
|
|
|
|
def remove(self, val):
|
|
"""
|
|
:type val: int
|
|
:rtype: bool
|
|
"""
|
|
if val not in self:
|
|
return False
|
|
self.discard(val)
|
|
return True
|
|
|
|
|
|
def getRandom(self):
|
|
"""
|
|
:rtype: int
|
|
"""
|
|
rand = r.self
|
|
return rand
|
|
|
|
|
|
|
|
# Your RandomizedSet object will be instantiated and called as such:
|
|
# obj = RandomizedSet()
|
|
# param_1 = obj.insert(val)
|
|
# param_2 = obj.remove(val)
|
|
# param_3 = obj.getRandom() |