diff --git a/Top150Interview/380InsertDeleteGetRandomO1.py b/Top150Interview/380InsertDeleteGetRandomO1.py index 531aea9..ea435cb 100644 --- a/Top150Interview/380InsertDeleteGetRandomO1.py +++ b/Top150Interview/380InsertDeleteGetRandomO1.py @@ -1,26 +1,36 @@ +import random as r + def __init__(self): - + self.set = {} def insert(self, val): """ :type val: int :rtype: bool """ - return True + 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 """ - return False + if val not in self: + return False + self.discard(val) + return True def getRandom(self): """ :rtype: int """ - return getRandom + return r.self