Implement Stack Using Array

Implement a stack using an array with the following operations:

  • push(x): Push element x onto stack
  • pop(): Removes the element on top of the stack
  • top(): Get the top element
  • empty(): 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]
Hints

Implement Stack Using Array

Implement a stack using an array with the following operations: