class Stack(object):
def __init__(self):
"""
initialize your data structure here.
"""
self.stack = []
def push(self, x):
"""
:type x: int
:rtype: nothing
"""
self.stack.append(x)
def pop(self):
"""
:rtype: nothing
"""
ele = self.stack[-1]
del self.stack[-1]
return ele
def top(self):
"""
:rtype: int
"""
return self.stack[-1]
def empty(self):
"""
:rtype: bool
"""
return len(self.stack) == 0
https://leetcode.com/problems/implement-stack-using-queues/#/description
Implement the following operations of a stack using queues.
Notes:
push to back
, peek/pop from front
, size
, and is empty
operations are valid.