class Solution {
public:
int myAtoi(string str) {
long long res = 0;
int sign = 1;
const int n=str.size();
int i=0;
<span style="white-space: pre;"> </span>while(str[i] ==' ' && i < n)
++i;
if(str[i] == '-' && i < n-1)
{
++i;
sign = -1;
}
else if(str[i] == '+' && i< n-1)
{
++i;
sign = 1;
}
while(str[i] >= '0' && str[i] <='9' && i<n)
{
res=10*res+str[i]-'0';
++i;
if(sign == 1 && res >= INT_MAX)
return INT_MAX;
if(sign == -1 && res > INT_MAX)
return INT_MIN;
}
return res*sign;
}
};