Simple Python Solution


  • 0
    Y
        def __init__(self):
            self.stack = []
            
        def push(self, x):
            self.stack.append(x)
            for i in range(0,len(self.stack)-1):
                self.stack.append(self.stack[0])
                self.stack.pop(0)
            
        def pop(self):
            self.stack.pop(0)
            
        def top(self):
            return self.stack[0]
    
        def empty(self):
            return not self.stack

Log in to reply
 

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