learning here!
I've managed to pull together this solution for a question on Leetcode! Heres the stats for this solution: Runtime: 1236 ms, faster than 17.28% of Python3 online submissions for Design HashSet Memory Usage: 18.7 MB, less than 83.53% of Python3 online submissions for Design HashSet.
Now - I wish that Leetcode would show an Ideal or Best practice solution just so I can compare and learn with mine! But they don't!
So, It would be appreciated if any of you can here! (Critique and show your Best practice solution)
My Solution
class MyHashSet:
def __init__(self):
"""
Initialize your data structure here.
"""
self.TheSet = []
def add(self, key: int) -> None:
if self.contains(key):
pass
else:
if key >= 0 and key <= 10**6:
self.TheSet.append(key)
else:
pass
def remove(self, key: int) -> None:
if self.contains(key):
self.TheSet.remove(key)
else:
pass
def contains(self, key: int) -> bool:
if key in self.TheSet:
return True
else:
return False
# Your MyHashSet object will be instantiated and called as such:
# obj = MyHashSet()
# obj.add(key)
# obj.remove(key)
# param_3 = obj.contains(key)```
