class Solution {
public:
int myAtoi(string str) {
if (str == "") return 0;
char* c = &str[0];
int num = 0;
int pos = 1;
while (*c == ' ') ++c;
if (*c == '-') {
pos = -1;
++c;
}
else if(*c == '+'){
++c;
}
while ('0' <= *c && *c <= '9') {
int n = (*c - '0')*pos;
if(num > INT_MAX / 10 || (num == INT_MAX / 10 && n > 7)) return INT_MAX;
if (num < INT_MIN / 10 || num == INT_MIN / 10 && n < -8) return INT_MIN;
num = num * 10 + n;
++c;
}
return num;
}
};