admin管理员组

文章数量:1636925

Implement Stack

Description:

Implement a stack. You can use any data structure inside a stack except stack itself to implement it.

Example
push(1)
pop()
push(2)
top() // return 2
pop()
isEmpty() // return true
push(3)
isEmpty() // return false

Code:

class Stack:
    stack = []
    """
    @param: x: An integer
    @return: nothing
    """
    def push(self, x):
        # write your code here
        self.stack.append(x)
    """
    @return: nothing
    """

    def pop(self):
        # write your code here
        return 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
        if self.stack:
            return False
        else:
            return True

本文标签: implementLintcodePythonEasyStack