思路:
一个栈入队列,一个栈出队列,当出队列为空时,将入队列栈全部压到出队列栈中
ps: 还得自己写构造函数
# -*- coding:utf-8 -*- class Solution: def __init__(self): self.stack1=[] self.stack2=[] def push(self, node): self.stack1.append(node) def pop(self): if self.stack2 ==[]: if not self.stack1: return None while self.stack1: self.stack2.append(self.stack1.pop()) return self.stack2.pop() return self.stack2.pop()