← 返回 amazon 的题目列表Implement Stack from Scratch
类型:online_judge
amazon
Design a stack using an object-oriented approach that supports the following operations:
push(x): Push element x onto stack.
pop(): Remove the element on top of the stack.
top(): Get the top element.
empty(): Return true if the stack is empty, otherwise false.
Constraints:
All operations must have O(1) complexity.
The stack is initially empty.
Example:
push(1)
push(2)
top() -> 2
pop() -> 2
empty() -> false
Example
Input
push 1
push 2
top
pop
empty