首页 > 其他 > 详细

155. 最小栈

时间:2020-05-16 14:16:44      阅读:46      评论:0      收藏:0      [点我收藏+]

技术分享图片
技术分享图片
技术分享图片

思路:

用list模拟栈,list的append()和pop()函数分别模拟进栈和出栈。

class MinStack(object):
    def __init__(self):
        """
        initialize your data structure here.
        """
        self.stack = []

    def push(self, x):
        """
        :type x: int
        :rtype: None
        """
        self.stack.append(x)

    def pop(self):
        """
        :rtype: None
        """
        self.stack.pop()

    def top(self):
        """
        :rtype: int
        """
        return self.stack[-1]

    def getMin(self):
        """
        :rtype: int
        """
        return min(self.stack)

155. 最小栈

原文:https://www.cnblogs.com/panweiwei/p/12900167.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!