Nice Solution!!! I like the way you solve the problem!

For those who cannot remember the INT_MAX (2147483647), you can alternatively use long integer (long long in c++) and return the result if the base is greater than INT MAX.

Since INT MIN and INT MAX differ 1 in absolute value, you don't need to worry about too many edge cases such as INT MIN .

This line handles everything.

```
if (base > INT_MAX)
return sign == 1 ? INT_MAX : INT_MIN;
```

Here is my solution:

```
int myAtoi(string str) {
int sign = 1, pt = 0;
long long base = 0;
while (str[pt] == ' ')
pt++;
if (str[pt] == '+' || str[pt] == '-')
sign = 1 - 2 * (str[pt++] == '-');
while (str[pt] >= '0' && str[pt] <= '9') {
base = 10 * base + (str[pt++] - '0');
if (base > INT_MAX)
return sign == 1 ? INT_MAX : INT_MIN;
}
return (int) (base * sign);
}
```