Leetcode-Easy 155. Min Stack
程序员文章站
2024-01-19 16:54:58
...
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()
上一篇: 数据结构——栈
推荐阅读
-
LeetCode 155. Min Stack
-
LeetCode_155-Min Stack
-
Leetcode-Easy 155. Min Stack
-
[LeetCode]155. Min Stack
-
155. Min Stack
-
LeetCode 第 155 题 (Min Stack)
-
LeetCode()- Min Stack
-
【每日一题】实现一个栈Stack,要求实现Push(出栈)、Pop(入栈)、Min(返回最小值的操作)的时间复杂度为O(1)
-
leetcode 155. 最小栈(开启一个辅助栈 每次push min(辅助栈栈顶,x))
-
LeetCode 第 155 题 (Min Stack)