" -0012a42" how come this should print -12??


  • 2
    A

    I was trying this question using python.
    Above test case is wrong, even python int(" -0012a42") gives error on this,(in our case this should return 0)
    PLEASE CORRECT TEST CASES OR GIVE PROPER EXPLAINATION!


  • 0
    J

    Your suppose to implement atoi from c not something similar to atoi.


  • 1
    S

    I agree with the above post. Why should "-0012a42" evaluate to -12? I thought the intention of the problem was to verify whether the given string can be converted to a valid int or not. If these cases are true, there could be infinitely many ways of extracting a number out of the given string. For example, what stops us from evaluating the above string to "-1242"?


  • 0
    J

    Nothing is stopping you from doing anything, if you were coding your own version of atoi, you can do as you like. But the question specifically ask you to code "atoi" which is already implemented in C and is what you need to follow.


Log in to reply
 

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