题解 | #用两个栈实现队列#
用两个栈实现队列
http://www.nowcoder.com/practice/54275ddae22f475981afa2244dd448c6
-- 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
if len(self.stack2) != 0:
return self.stack2.pop()
else:
for i in range(len(self.stack1)):
item = self.stack1.pop()
self.stack2.append(item)
return self.stack2.pop()