class Solution {
public:
int strToInt(string str) {
double res = 0,sign = 1;
for(int i = 0; i < str.size(); i ++){
if (str[i] == ' ' || str[i] == '+') continue;
if (str[i] == '-') {
sign = -1;
continue;
};
if (!(str[i] >= '0' && str[i] <= '9')) break;
res = res * 10 + str[i] - '0';
}
res *= sign;
if (res < INT_MIN) res = INT_MIN;
if (res > INT_MAX) res = INT_MAX;
return res;
}
};