Implement Stack Using Array
Implement a stack using an array with the following operations:
push(x): Push element x onto stackpop(): Removes the element on top of the stacktop(): Get the top elementempty(): Return whether the stack is empty
Given an array of operations and values, execute them and return the results.
Examples
Input: [["push","push","top","pop","empty"],[1,2,0,0,0]]
Output: [2,false]
Input: [["push","pop","empty"],[1,0,0]]
Output: [true]
Hints
Initialize a variable to keep track of the top index of the stack (initially -1 for an empty stack).
Related Problems
Implement Stack Using Array
Implement a stack using an array with the following operations: