Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lwb58 committed Aug 9, 2020
0 parents commit dc8a38f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/stack/minStack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class MinStack:
def __init__(self):
self.stack=[]
def push(self,value):
if not self.stack:
self.stack.append((value,value))
else:
self.stack.append((value,min(value,self.stack[-1][1])))
def pop(self):
self.stack.pop()[0]
def top(self):
return self.stack[-1][0]
def getMin(self):
return self.stack[-1][1]
if __name__ == '__main__':
test = MinStack()
test.push(-2)
test.push(0)
test.push(-3)
print(test.getMin())
print(test.pop())
print(test.top())
print(test.getMin())

0 comments on commit dc8a38f

Please sign in to comment.