微信图片_20191221152107.jpg
class Solution:
def __init__(self):
self.stack = []
self.min_stack = []
def push(self, node):
# write code here
self.stack.append(node)
if self.min_stack == []:
self.min_stack.append(node)
else:
if node <= self.min_stack[-1]:
self.min_stack.append(node)
else:
self.min_stack.append(self.min_stack[-1])
def pop(self):
# write code here
if self.stack:
self.min_stack.pop()
return self.stack.pop()
def top(self):
# write code here
if self.stack:
return self.stack[-1]
def min(self):
# write code here
if self.min_stack:
return self.min_stack[-1]
网友评论