A lazy C++ method using system API


  • 1
    M
    class Solution {
    public:
        int myAtoi(string str) {
            const char *tmp=str.c_str();
            long val = 0;
            sscanf(tmp,"%ld",&val);
            if((long)((int)val)!=val)
            {
                if(val>0)
                    return INT_MAX;
                else
                    return INT_MIN;
            }
            return val;
        }
    };

Log in to reply
 

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