描述
实现一个栈,可以使用除了栈之外的数据结构
样例
例1:
输入:
push(1)
pop()
push(2)
top() // return 2
pop()
isEmpty() // return true
push(3)
isEmpty() // return false
例2:
输入:
isEmpty()
class Stack:
"""
@param: x: An integer
@return: nothing
"""
def __init__(self):
self.stack = []
def push(self, x):
# write your code here
self.stack.append(x)
"""
@return: nothing
"""
def pop(self):
# write your code here
self.stack.pop()
"""
@return: An integer
"""
def top(self):
# write your code here
return self.stack[-1]
"""
@return: True if the stack is empty
"""
def isEmpty(self):
# write your code here
return len(self.stack) == 0