/** * Initialize your data structure here. */ var MyStack = function() { this.stack = []; };
/** * Push element x onto stack. * @param {number} x * @return {void} */ MyStack.prototype.push = function(x) { const stack = this.stack; stack.push(x); };
/** * Removes the element on top of the stack and returns that element. * @return {number} */ MyStack.prototype.pop = function() { const stack = this.stack; return stack.pop(); };
/** * Get the top element. * @return {number} */ MyStack.prototype.top = function() { const stack = this.stack; return stack[stack.length - 1]; };
/** * Returns whether the stack is empty. * @return {boolean} */ MyStack.prototype.empty = function() { returnthis.stack.length === 0; };