leetcode——155. 最小栈

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

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11782407.html