两个栈实现一个队列
class Solution(object):
"""
两个栈实现一个队列
"""
def __init__(self):
# -----
self.stack1 = []
self.stack2 = []
def push(self, element):
self.stack1.append(element)
def pop(self):
if self.stack2 == [] and self.stack1 == []:
raise IndexError("index out of range, stack is empty now!")
for val in range(len(self.stack1)):
self.stack2.append(self.stack1.pop(0))
return self.stack2.pop(0)
life is a boat
相关推荐
开发者工具
请我喝咖啡
如果内容帮到了你,可以赞赏支持继续更新。
赏