题解 | 包含min函数的栈

# -*- coding:utf-8 -*-
class Solution:
    def __init__(self):
        # 初始化实例属性 stack
        self.stack = []

    def push(self, node):
        # write code here
        self.stack.append(node)
    def pop(self):
        # write code here
        if self.stack:
            return self.stack.pop()
        return None

    def top(self):
        # write code here
        if self.stack:
            return self.stack[-1]
        return None

    def min(self):
        # write code here
        if self.stack:
            return min(self.stack)
        return None

直接用[-1]和min就行了

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务