class Solution {
public:
int maxEdge = INT_MAX / 10;
int minEdge = INT_MIN / 10;
int maxSV = INT_MAX % 10;
int minSV = INT_MIN % 10;
int strToInt(string str) {
int n = str.size();
if(n <= 0) return 0;
int left = 0;
bool is_Minus = false;
int res = 0;
while(left < n && str[left] == ' ') left ++ ;
if(str[left] == '+') left ++ ;
else if(str[left] == '-')
{
left ++ ;
is_Minus = true;
}
int k = left;
//cout << k <<endl;
while(k < n && str[k] >= '0' && str[k] <= '9')
{
if(is_Minus){
int t = (- 1) * (str[k] - '0');
if(res < minEdge) return INT_MIN;
if(res == minEdge)
{
if(t < minSV) return INT_MIN;
}
res = res * 10 +t;
}
else
{
int t = str[k] - '0';
//cout << t << endl;
if(res > maxEdge) return INT_MAX;
if(res == maxSV)
{
if(t >= maxSV) return INT_MAX;
}
else res = res * 10 + t;
//cout << res << endl;
}
k++;
}
return res;
}
};