Skip to content

Commit e71c1db

Browse files
authored
MinStack day10
1 parent e0e259f commit e71c1db

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

Leetcode_30days/day10_MinStack.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
class MinStack(object):
2+
3+
def __init__(self):
4+
"""
5+
initialize your data structure here.
6+
"""
7+
self.A =[]
8+
9+
def push(self, x):
10+
"""
11+
:type x: int
12+
:rtype: None
13+
"""
14+
self.A.append(x)
15+
16+
17+
def pop(self):
18+
"""
19+
:rtype: None
20+
"""
21+
if self.A:
22+
self.A.pop()
23+
24+
25+
def top(self):
26+
"""
27+
:rtype: int
28+
"""
29+
if self.A:
30+
return self.A[-1]
31+
else:
32+
return None
33+
34+
35+
36+
def getMin(self):
37+
"""
38+
:rtype: int
39+
"""
40+
if self.A:
41+
return min(self.A)
42+
else:
43+
return None
44+
45+
46+
47+
# Your MinStack object will be instantiated and called as such:
48+
# obj = MinStack()
49+
# obj.push(x)
50+
# obj.pop()
51+
# param_3 = obj.top()
52+
# param_4 = obj.getMin()

0 commit comments

Comments
 (0)