ImplementQueueUsingStacks
Published at 2021-11-16
class MyQueue:
def __init__(self):
self.stack = []
def push(self, x: int) -> None:
self.stack.append(x)
def pop(self) -> int:
if self.stack:
return self.stack.pop(0)
else:
return []
def peek(self) -> int:
if self.stack:
return self.stack[0]
else:
return []
def empty(self) -> bool:
if self.stack:
return False
else:
return True
# Your MyQueue object will be instantiated and called as such:
# obj = MyQueue()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.peek()
# param_4 = obj.empty()