【栈】包含min函数的栈

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]

你可能感兴趣的:(【栈】包含min函数的栈)