【栈】包含min函数的栈
2019-10-10 本文已影响0人
一个想当大佬的菜鸡
class Solution:
def __init__(self):
self.stack = []
self.helper = []
def push(self, node):
self.stack.append(node)
if self.helper:
self.helper.append(min(node,self.helper[-1]))
else:
self.helper.append(node)
def pop(self):
self.stack.pop()
self.helper.pop()
def min(self):
return self.helper[-1]
def top(self):
return self.stack[-1]