def__init__(self): """ Initialize your data structure here. """ self.stack = []
defpush(self, x: int) -> None: """ Push element x onto stack. """ self.stack.append(x)
defpop(self) -> int: """ Removes the element on top of the stack and returns that element. """ return self.stack.pop()
deftop(self) -> int: """ Get the top element. """ return self.stack[-1]
defempty(self) -> bool: """ Returns whether the stack is empty. """ returnTrueifnot self.stack elseFalse
# 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()