Hi,

It seems that my code cannot deal with the test case: "9223372036854775809".

As I walk through the code step by step, I found that when I do

result = result*10 + str[i] - '0';

922337203685477580 + '9' - '0' = -9223372036854775807

For your information: I declare result as long long type. Here is my code:

int atoi(const char *str) {

long long result=0;

int sign=1, i;

for (i=0; str[i]==' '; ++i);//skip the spaces

```
sign = (str[i]=='-')?(-1):1;
if (str[i] == '+' || str[i] == '-')
i++;
for (result = 0; str[i]>='0' && str[i]<='9'; ++i) {//do if str[i] is a digit.
result = 10 * result + (str[i]-'0');
}
result *= sign;
if(result > INT_MAX) return INT_MAX;
else if(result < INT_MIN) return INT_MIN;
else return result;
```

}

Thanks!