My simple python solution


  • 0
    G

    class Stack(object):
    def init(self):
    """
    initialize your data structure here.
    """
    self.stack = []

    def push(self, x):
        """
        :type x: int
        :rtype: nothing
        """
        self.stack = [x] + self.stack
        
    
    def pop(self):
        """
        :rtype: nothing
        """
        self.stack = self.stack[1:]
        
    
    def top(self):
        """
        :rtype: int
        """
        return self.stack[0]
    
    def empty(self):
        """
        :rtype: bool
        """
        return len(self.stack) == 0

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.