leetcode——155. 最小栈

不打扰是莪最后的温柔 提交于 2019-12-03 07:10:13
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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!