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
29 changes: 29 additions & 0 deletions problem1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Design-1

## Problem 1:(https://leetcode.com/problems/design-hashset/)

class MyHashSet:

def __init__(self):
self.hash_set = []

def add(self, key: int) -> None:
# add only if it doesnt exist
if not self.contains(key):
self.hash_set.append(key)

def remove(self, key: int) -> None:
if self.contains(key):
self.hash_set.remove(key)

def contains(self, key: int) -> bool:
if key in self.hash_set:
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)
30 changes: 30 additions & 0 deletions problem2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Problem 2:
## Design MinStack (https://leetcode.com/problems/min-stack/)

class MinStack:

def __init__(self):
self.min_stack = []

def push(self, val: int) -> None:
self.min_stack.append(val)

def pop(self) -> None:
self.min_stack = self.min_stack[:-1]

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

def getMin(self) -> int:
min_val = self.min_stack[0]
for i in range(1,len(self.min_stack)):
if self.min_stack[i] < min_val:
min_val = self.min_stack[i]
return min_val

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