class MyStack:
def __init__(self):
"""
Initialize your data structure here.
"""
self.l1=[]
self.l2=[]
def push(self, x: int) -> None:
"""
Push element x onto stack.
"""
self.l1.append(x)
def pop(self) -> int:
"""
Removes the element on top of the stack and returns that element.
"""
if not self.l1:
return None
l=len(self.l1)-1
for i in range(l):
self.l2.append(self.l1.pop(0))
num=self.l1.pop(0)
l2=len(self.l2)
for j in range(l2):
self.l1.append(self.l2.pop(0))
return num
def top(self) -> int:
"""
Get the top element.
"""
if not self.l1:
return None
l=len(self.l1)
for i in range(l):
if i==l-1:
num=self.l1[0]
self.l2.append(self.l1.pop(0))
l2=len(self.l2)
for j in range(l2):
self.l1.append(self.l2.pop(0))
return num
def empty(self) -> bool:
"""
Returns whether the stack is empty.
"""
if self.l1 or self.l2:
return False
return True
# Your MyStack object will be instantiated and called as such:
# obj = MyStack()
# obj.push(x)
# param_2 = obj.pop()
# param_3 = obj.top()
# param_4 = obj.empty()