What is wrong with this simple python code (MLE) problem?


  • 0
    X

    I have the following python code that I thought was simple enough and it considers the empty stack problem. What is wrong with it?

    class MinStack:
        def __init__(self):
            self.setS=[]
    
        def Empty(self):
            return len(self.setS)==0
    
        def push(self,x):
            if(self.Empty()):
                self.setS.append((x,x))
            else:
                mval=min(self.setS[-1][1],x)
                self.setS.append((x,mval))
    
        def top(self):
            if(self.Empty()):return
            return self.setS[-1][0]
    
        def pop(self):
            if(self.Empty()):return
            self.setS.pop()
    
        def getMin(self):
            if(self.Empty()):return
            return self.setS[-1][1]

Log in to reply
 

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