classMyStack:def__init__(self):"""
Initialize your data structure here.
"""
self.q1 =[]
self.q2 =[]
self.tp =Nonedefpush(self, x:int)->None:"""
Push element x onto stack.
"""
self.tp = x
self.q1.append(x)defpop(self)->int:"""
Removes the element on top of the stack and returns that element.
"""whilelen(self.q1)!=1:
self.tp = self.q1.pop(0)
self.q2.append(self.tp)
res = self.q1.pop(0)
self.q1, self.q2 = self.q2, self.q1
return res
deftop(self)->int:"""
Get the top element.
"""return self.tp
defempty(self)->bool:"""
Returns whether the stack is empty.
"""return self.q1 ==[]