剑指offer python版 包含min函数的栈
class minstack(object): def __init__(self): self.stack=[] self.min=[] def push(self,values): for i in values: self.stack.append(i) if self.min and self.min[-1]<i: self.min.append(self.min[-1]) else: self.min.append(i) def pop(self): self.min.pop() return self.stack.pop() def minn(self): return self.min[-1] a=minstack() a.push([1,2,3,4,5]) print(a.pop()) print(a.minn())