# -*- coding:utf-8 -*- class Solution: def __init__(self): self.stack1 = [] self.stack2 = [] def push(self, node): # write code here self.stack1.append(node) def pop(self): # return xx # 栈1的内容倒序全部搬到栈2,pop成功后,把栈2剩下的内容搬回栈1 while self.stack1: self.stack2.append(self.stack1.pop()) res = self.stack2.pop() # 如果不把栈2剩下的内容搬回栈1,就不能保证2在3之前出 # 1入,2入,1出,3入,2出 while self.stack2: self.stack1.append(self.stack2.pop()) return res