Problem does not follow requirements for standard atoi


  • 1
    G

    A solution that looks like this does not pass

    int myAtoi(string str) {
      return atoi(str.c_str());
    }
    

    For example, when parsing string "2147483648" the standard atoi implementation returns -2147483648, while this implementation expects a return value of 2147483647. I'm not sure if this is specified or not in c++ standard API, or if it can be implementation specific.

    Is this done by intention or is there another reason why the result does not yield the same result as the standard atoi?


  • 0
    Z
    This post is deleted!

  • 0
    G

    Yes, I know how to solve the question. It is just that edge cases that I think should be mentioned in the problem formulation is not there. They should at least be mentioned after requesting hints.


  • 1
    J

    My atoi return the value 2147483647.(use vs2013)


  • 0
    G

    OK. That explains why. It is implementation specific. I dont use Windows so much nowadays anyway.


  • 0

    This question is silly


Log in to reply
 

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