forked from HarshRangwala/Interview-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMin Stack.py
More file actions
47 lines (38 loc) · 729 Bytes
/
Min Stack.py
File metadata and controls
47 lines (38 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 10 16:47:38 2019
@author: Anuj
"""
class minStack(object):
def __init__(self):
# Fill this in.
self.stack = []
def push(self, x):
# Fill this in.
self.stack.append(x)
def pop(self):
# Fill this in.
if self.stack:
self.stack.pop()
def top(self):
# Fill this in.
if self.stack:
top = self.stack.pop()
self.stack.append(top)
return top
def getMin(self):
# Fill this in.
return min(self.stack)
x = minStack()
x.push(-2)
x.push(0)
x.push(-3)
#print("STACK ",x.stack)
print(x.getMin())
# -3
x.pop()
#print("STACK ",x.stack)
#print(x.stack[x.top])
print(x.top())
# 0
print(x.getMin())