class Solution {
public:
int strToInt(string str) {
int k=0; //字符串的head
while(k<str.size()&&str[k]==' ') k++;
bool is_minus =false;
long long num=0;
if(str[k]=='+') k++;
else if(str[k]=='-') is_minus=true,k++;
while(k<str.size()&&str[k]>='0'&&str[k]<='9'){
num =num*10+(str[k]-'0');
k++;
}
if(is_minus) num*=-1;
if(num > INT_MAX) num = INT_MAX;
if(num < INT_MIN) num = INT_MIN;
return (int) num;
}
};