From e51f102bc4f44c9ee9e9957b8ab523d4583ba76c Mon Sep 17 00:00:00 2001 From: SinAIML Date: Tue, 14 Apr 2026 22:41:40 -0700 Subject: [PATCH] done design -1 --- design-hashset.py | 35 +++++++++++++++++++++++++++++++ design-minstack.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 design-hashset.py create mode 100644 design-minstack.py diff --git a/design-hashset.py b/design-hashset.py new file mode 100644 index 00000000..99637d73 --- /dev/null +++ b/design-hashset.py @@ -0,0 +1,35 @@ +class MyHashSet(object): + + def __init__(self): + self.data = [False] * (10**6 + 1) + + + def add(self, key): + """ + :type key: int + :rtype: None + """ + self.data[key] = True + + def remove(self, key): + """ + :type key: int + :rtype: None + """ + self.data[key] = False + + + + def contains(self, key): + """ + :type key: int + :rtype: bool + """ + return self.data[key] + + +# Your MyHashSet object will be instantiated and called as such: +# obj = MyHashSet() +# obj.add(key) +# obj.remove(key) +# param_3 = obj.contains(key) \ No newline at end of file diff --git a/design-minstack.py b/design-minstack.py new file mode 100644 index 00000000..05ae0c76 --- /dev/null +++ b/design-minstack.py @@ -0,0 +1,51 @@ +class MinStack(object): + + def __init__(self): + self.stack = [] + self.minstack = [] + + def push(self, val): + """ + :type val: int + :rtype: None + """ + self.stack.append(val) + + #if minstack is empty + if not self.minstack: + self.minstack.append(val) + #if minstack is not empty + elif self.minstack[-1] < val: + self.minstack.append(self.minstack[-1]) + else: # if val is less than min + self.minstack.append(val) + + + def pop(self): + """ + :rtype: None + """ + self.stack.pop() + self.minstack.pop() + + + def top(self): + """ + :rtype: int + """ + return self.stack[-1] + + + def getMin(self): + """ + :rtype: int + """ + return self.minstack[-1] + + +# Your MinStack object will be instantiated and called as such: +# obj = MinStack() +# obj.push(val) +# obj.pop() +# param_3 = obj.top() +# param_4 = obj.getMin() \ No newline at end of file