My simple python solution


  • 0
    G

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

    def push(self, x):
        """
        :type x: int
        :rtype: nothing
        """
        self.data = [x] + self.data
    
    def pop(self):
        """
        :rtype: nothing
        """
        if len(self.data) > 0:
            self.data.pop()
    
    def peek(self):
        """
        :rtype: int
        """
        return self.data[-1]
    
    def empty(self):
        """
        :rtype: bool
        """
        return len(self.data) == 0

Log in to reply
 

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