用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 21 19:39:26 2018
@author: Saul
"""
# -*- coding:utf-8 -*-
class Solution:
def __init__(self):
self.stack1 = []
self.stack2 = []
def push(self, node):
# write code here
self.stack1.insert(0,node)
def pop(self):
# return xx
if len(self.stack2) != 0:
return self.stack2.pop(0)
elif len(self.stack1) == 0:
return
else:
self.stack2 = self.stack1[::-1]
self.stack1 = []
return self.stack2.pop(0)