Wrong code but accpted


  • 0
    N
    class MinStack:
                # @param x, an integer
                # @return an integer
                def __init__(self):
                    self.data=[]
                    self.minl=[]
                    self.minn=0
                def push(self, x):
                    if len(self.minl)==0 or x<self.getMin():
                        self.minl.append(x)
                        self.minn=1
                    elif x==self.getMin():
                        self.minn+=1
                    self.data.append(x)
                # @return nothing
                def pop(self):
                    d=self.data.pop()
                    if d==self.getMin():
                        self.minn-=1
                        if self.minn==0:
                            self.minl.pop()
                            self.minn=1
            
                # @return an integer
                def top(self):
                    return self.data[-1]
            
                # @return an integer
                def getMin(self):
                    return self.minl[-1]
    

    the code will faill when:
    push(2) push(2) push(1) pop() pop() getMin
    but pass the test


  • 1
    S

    Have you tried to submit this code?

    This code won't pass the judge, but get Runtime Error instead.


  • 0
    N

    sorry,i change the code just now


  • 0
    N

    you can test the changed one


Log in to reply
 

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