# -*- coding:utf-8 -*- class Solution: def __init__(self): self.stack = [] self.min_stack = [] def push(self, node): # write code here self.stack.append(node) if not self.min_stack: self.min_stack.append(node) elif 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 self.min_stack.pop() return self.stack.pop() def top(self): # write code here return self.stack[-1] def min(self): # write code here return self.min_stack[-1]