Unexpected Output in OJ different from my actual output


  • 1
    K

    The below test case yields an unexpected output unlike the one produced on my laptop. I am curious on how the output was generated. Below is my code solution for the problem. Could anyone help me debug this test case?

    Input: push(-1),top,getMin
    Output: [-3,-1]
    Expected: [-1,-1]

    class MinStack:
        # @param x, an integer
        # @return an integer
        top_elem = -1
        min = float('inf')
        stack = []
    
        def push(self, x):
            if x < self.min:
                self.min = x
            self.stack.append(x)
            self.top_elem += 1
        # @return nothing
    
        def pop(self):
            if self.top_elem == -1:
                return
            element = self.stack.pop()
            self.top_elem -= 1
            if element == self.min:
                self.min = float('inf')
                for item in self.stack:
                    if item < self.min:
                        self.min = item
            return
    
        # @return an integer
        def top(self):
            if self.top_elem != -1:
                return self.stack[self.top_elem]
    
        # @return an integer
        def getMin(self):
            if self.top_elem != -1
                return self.min

  • 1
    G

    I got the same problem, I think OJ is trying to evaluate [self.stack, self.min]

    No idea where that -3 is coming from though ..


  • 0
    K

    should we report this to OJ. I was wondering it was only my problem.


  • 0
    G

  • 0
    S

    Give my vote up for your name.


Log in to reply
 

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