思路:
从FILO到FIFO的操作,出栈指定0即可
class MyQueue(object):
def __init__(self):
"""
Initialize your data structure here.
"""
self.stack = []
def push(self, x):
"""
Push element x to the back of queue.
:type x: int
:rtype: None
"""
self.stack.append(x)
def pop(self):
"""
Removes the element from in front of queue and returns that element.
:rtype: int
"""
if self.empty():
return False
return self.stack.pop(0)
def peek(self):
"""
Get the front element.
:rtype: int
"""
if self.empty():
return False
return self.stack[0]
def empty(self):
"""
Returns whether the queue is empty.
:rtype: bool
"""
return len(self.stack) == 0