欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

155.最小堆叠

最编程 2024-10-05 07:14:46
...
class MinStack(object): def __init__(self): self.stack=[] def push(self, val): """ :type val: int :rtype: None """ self.stack.append(val) def pop(self): """ :rtype: None """ self.stack.pop() def top(self): """ :rtype: int """ return self.stack[-1] def getMin(self): """ :rtype: int """ return min(self.stack) # Your MinStack object will be instantiated and called as such: # obj = MinStack() # obj.push(val) # obj.pop() # param_3 = obj.top() # param_4 = obj.getMin()