欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Leetcode-Easy 155. Min Stack

程序员文章站 2024-01-19 16:54:58
...

234. Palindrome Linked List

  • 描述:
    栈的实现


    Leetcode-Easy 155. Min Stack
  • 思路:
    通过列表进行实现

  • 代码

class MinStack:

    def __init__(self):
        """
        initialize your data structure here.
        """
        self.data=[]
    def push(self, x):
        """
        :type x: int
        :rtype: void
        """
        self.data.append(x)
    def pop(self):
        """
        :rtype: void
        """
        self.data=self.data[:-1]
        
    def top(self):
        """
        :rtype: int
        """
        return self.data[-1]
        

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


# 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()