class Solution {
public:
long long strToInt(string str) {
int k=0;
while(k<str.size()&&str[k]==' ') k++;
int mio=1;
if(k<str.size())
{
if(str[k]=='-')
{
mio=-1;
k++;
}
else if(str[k]=='+') k++;
}
long long sum=0;
while(k<str.size()&&str[k]>='0'&&str[k]<='9')
{
sum=sum*10+str[k]-'0';
if(sum>INT_MAX){
break;
}
k++;
}
sum=sum*mio;
if(sum>INT_MAX)
{
sum=INT_MAX;
}
if(sum<INT_MIN) sum=INT_MIN;
return sum;
}
};