My simple and clear python solution:


  • -2
    F

    My simple and clear python solution:

    class Queue(object):
        def __init__(self):
            """
            initialize your data structure here.
            
            """
            self.stack=[]
    
        def push(self, x):
            """
            :type x: int
            :rtype: nothing
            """
            self.stack.append(x)
            
    
        def pop(self):
            """
            :rtype: nothing
            """
            return self.stack.pop(0)
            
    
        def peek(self):
            """
            :rtype: int
            """
            return self.stack[0]
            
    
        def empty(self):
            """
            :rtype: bool
            """
            return len(self.stack)==0

  • 1
    D

    pop(0) is not an operation for stack.


  • 0
    F

    I didn't say I use stack, I just use the variable name like stack. You need look at the code to see it's stack or not!


  • 0
    M

    but if your answer doesn't follow the conditions of question,what's the meaning here?


Log in to reply
 

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