Sword_Offer 用两个栈实现队列[9]
Sword_Offer 用两个栈实现队列[9]
0x00 题目描述
实现队列的头部删除和尾部添加
0x01 解题思路
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# Author LQ6H
class Solution:
def __init__(self):
self.stack1=[]
self.stack2=[]
def push(self,node):
return self.stack1.append(node)
def pop(self):
if self.stack2==[]:
while self.stack1:
self.stack2.append(self.stack1.pop())
return self.stack2.pop()