The output is:Last executed input: ""


  • 0
    T

    this is my C++ code

    class Solution {
        public:
            int atoi(const char *str) {
        		assert( str!= NULL);
        		long long res = 0;
        		bool flag = true;
        		while (isspace(*++str));
                if ( (*str == '+') || (*str == '-'))
        			flag = ( *str++ != '-');
        		while (*str == '\0')
        			str++;
        		while (isdigit(*str))
        			res = res*10 + (*str++-'0');
        		res = flag == true ? res : -res;
        
        		if(res>INT_MAX) return INT_MAX;
                else if(res<INT_MIN) return INT_MIN;
                else return res;
            }
        };

  • 0
    T

    Last executed input: "",i think when input is "",the output shoud be 0,but what's the wrong with my code?


Log in to reply
 

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