Why +-2 the expected value is 0 instead of -2


  • 1
    D

    why +-2 the expected value is 0 instead of -2


  • 0
    V

    I have same question


  • 0
    M

    It's because, according to the documentation, starting from the first non-whitespace character, an optional initial plus or minus sign (in this case, '+') followed by as many base-10 digits as possible (in this case, '-2'). The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function.

    Obviously, "-2" is not a string of "base-10 digits", so it is interpreted as "additional characters", which are simply ignored.


Log in to reply
 

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