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