Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions design-hashset.py
Original file line number Diff line number Diff line change
@@ -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)
51 changes: 51 additions & 0 deletions design-minstack.py
Original file line number Diff line number Diff line change
@@ -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()