class Solution {
public:
int myAtoi(string str) {
int i = 0;
int sym = 1;//判断符号
long long res = 0;
while(i < str.size() && str[i] == ' ') i += 1;
if(str[i] == '-') {sym = -1;i += 1;}
else if(str[i] == '+'){i += 1;}
while(i < str.size() && str[i] >= '0' && str[i] <= '9'){
res = res * 10 + str[i++] - '0';//char类型转int类型
if(res >= 2147483648){
if(sym == 1) return INT_MAX;
else return INT_MIN;
}
}
return res * sym;
}
};