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