Why is this a wrong answer?


  • 0
    N

    Input:
    -2147483648
    -1

    Output:
    2147483648

    Expected:
    2147483647


  • 1
    T

    the max value of a int 32 is 2^32-1 = 2,147,483,647, and the minimum value is -2^32 = -2147483648. It's just how it is when the answer for the leetcode question uses int32.


  • 0
    N

    Exactly, and it makes this a very good test case to verify your algorithm, although obviously the judge itself failed in this one.


  • 0
    T

    I am guessing you are using python. In Python int and long are unified, so the answer would not be limited to the limit of int32.


  • 0
    N

    You are right. I manually defined INT_MAX and INT_MIN to curb the output and successfully pass the OJ. Thanks for your comments!


Log in to reply
 

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