题目描述:
解决代码:
class MyQueue:
def __init__(self):
"""
Initialize your data structure here.
"""
self.A = []
self.B = []
def push(self, x: int) -> None:
"""
Push element x to the back of queue.
"""
self.A.append(x)
def pop(self) -> int:
"""
Removes the element from in front of queue and returns that element.
"""
if self.empty():
return
if len(self.B) == 0:
while len(self.A) != 0:
self.B.append(self.A.pop())
return self.B.pop()
else:
return self.B.pop()
def peek(self) -> int:
"""
Get the front