File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,19 +4,20 @@ def __init__(self):
44 # main stack for storing elements
55 self .minSt = []
66 # auxiliary stack for finding minimum in O(1) time space O(N) because of this auxiliary stack using
7- # pushing new element
7+
8+ # pushing new element
89 def push (self , x ):
910 self .st .append (x )
10-
11- # If minSt is empty or new element is smaller than
11+
12+ # If minSt is empty or new element is smaller than
1213 # the top of minSt, push it because if it is empty then coming element will be minimum and if coming element is smaller than previous
1314 if not self .minSt or x <= self .minSt [- 1 ]:
1415 self .minSt .append (x )
15-
16+
1617 # Pop the top element
1718 def pop (self ):
1819 if not self .st :
19- return None
20+ return None
2021 value = self .st .pop ()
2122 if value == self .minSt [- 1 ]:
2223 self .minSt .pop ()
@@ -35,15 +36,15 @@ def getMin(self):
3536 return self .minSt [- 1 ]
3637
3738
38- if __name__ == ' __main__' :
39+ if __name__ == " __main__" :
3940 st = MinStack ()
4041 # making new minstack object
41- #adding new elements
42+ # adding new elements
4243 st .push (18 )
4344 st .push (19 )
4445 st .push (29 )
4546 st .push (15 )
4647 st .push (16 )
47-
48+
4849 print (st .getMin ())
4950 # should return 15
You can’t perform that action at this time.
0 commit comments