【剑指offer】用两个栈实现队列(python)
1. 需要 init 构造函数给对象传递两个 stack 。
2. 列表为空 = False
3. arr.pop(),arr.append()
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 not self.stack2:
while(self.stack1):
self.stack2.append(self.stack1.pop())
return self.stack2.pop()
京公网安备 11010502036488号