Leetcode-Easy 155. Min Stack

时间:2022-05-08
本文章向大家介绍Leetcode-Easy 155. Min Stack,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

234. Palindrome Linked List

  • 描述: 栈的实现
  • 思路: 通过列表进行实现
  • 代码
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()