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
32 changes: 32 additions & 0 deletions designHashset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class MyHashSet:

def __init__(self):
self.hashSet=[]
primary = 10000
secondary = 10000
def key1(self,index):
return index%primary
def key2(self,index):
return index//secondary

def add(self, key: int) -> None:
if not key in self.hashSet:
self.hashSet.append(key)

def remove(self, key: int) -> None:
if key in self.hashSet:
self.hashSet.remove(key)


def contains(self, key: int) -> bool:
if key in self.hashSet:
return True
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)
37 changes: 37 additions & 0 deletions minStack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class MinStack:

def __init__(self):
self.arr = []
self.st = []
self.minValue = float("inf")
self.st.append(self.minValue)


def push(self, val: int) -> None:
self.minValue = min(val, self.minValue)
self.arr.append(val)

self.st.append(self.minValue)


def pop(self) -> None:
self.arr.pop()
self.st.pop()
self.minValue = self.st[-1]


def top(self) -> int:
return self.arr[-1]


def getMin(self) -> int:
return self.minValue



# 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()