Is the test case wrong


  • 0
    Y

    Input:
    ["MinStack","push","push","push","getMin","top","pop","getMin"]
    [[],[-2],[0],[-1],[],[],[],[]]
    Output:
    [null,null,null,null,-2,0,null,-1]
    Expected:
    [null,null,null,null,-2,-1,null,-2]

    How can the top be -1 ?


  • 0

    Top() is the top of the stack, not top of the minimums.
    -1 was the last pushed on the stack.
    After popping off -1, the minimum is still -2, which was the first pushed on.

    Check your code logic. :-)


Log in to reply
 

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