Leetcode-Easy 155. Min Stack

简介: Leetcode-Easy 155. Min Stack

234. Palindrome Linked List


  • 描述:
    栈的实现

    5.png
  • 思路:
    通过列表进行实现
  • 代码

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


相关文章
|
算法 安全 Java
【数据结构与算法】6、栈(Stack)的实现、LeetCode:有效的括号
【数据结构与算法】6、栈(Stack)的实现、LeetCode:有效的括号
83 0
|
存储 算法 测试技术
从小白开始刷算法 Stack 栈篇 leetcode.496
从小白开始刷算法 Stack 栈篇 leetcode.496
|
算法
从小白开始刷算法 Stack 栈篇 leetcode.20
从小白开始刷算法 Stack 栈篇 leetcode.20
152 0
LeetCode 225. Implement Stack using Queues
使用队列实现栈的下列操作: push(x) -- 元素 x 入栈; pop() -- 移除栈顶元素; top() -- 获取栈顶元素; empty() -- 返回栈是否为空
121 0
LeetCode 225. Implement Stack using Queues
LeetCode 225:用队列实现栈 Implement Stack using Queues
题目: 使用队列实现栈的下列操作: push(x) -- 元素 x 入栈 pop() -- 移除栈顶元素 top() -- 获取栈顶元素 empty() -- 返回栈是否为空 Implement the following operations of a stack using queues.
1107 0
LeetCode 155:最小栈 Min Stack
LeetCode 155:最小栈 Min Stack 设计一个支持 push,pop,top 操作,并能在常数时间内检索到最小元素的栈。 push(x) -- 将元素 x 推入栈中。 pop() -- 删除栈顶的元素。
847 0