What does this case mean "+-2"


  • 1
    M

    I don't even know what does "+-2" mean, and I supposed the result should be -2 but the expected value is "0", why is that?


  • 0
    D

    the first '+' is treated as a normal character as it has no digits immediately after it, and so, it renders everything after it unusable... as there is no answer you have to return 0


  • 0
    S

    if there is no answer, It's better to throw an exception rather than return a 0. That makes no difference between answer=0 and no answer.


  • 0
    D

    you might be right depending on the need, however the problem specifically states this should be the behavior


Log in to reply
 

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