首页 > 其他 > 详细

leetcode——155. 最小栈

时间:2019-11-02 16:26:57      阅读:64      评论:0      收藏:0      [点我收藏+]
class MinStack(object):

    def __init__(self):
        """
        initialize your data structure here.
        """
        self._elem=[]
        

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

    def pop(self):
        """
        :rtype: None
        """
        return self._elem.pop()
        

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

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


# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(x)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.getMin()
执行用时 :660 ms, 在所有 python 提交中击败了24.93%的用户
内存消耗 :15.5 MB, 在所有 python 提交中击败了19.17%的用户
 
——2019.11.2

leetcode——155. 最小栈

原文:https://www.cnblogs.com/taoyuxin/p/11782407.html

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