int myAtoi(char* str) {
long long ans = 0;
int flag = 1;
int be = 0;
while(str[be]==' ')be++;
if(str[be]=='-')
{
flag = -1;
be++;
}else if(str[be] == '+')
{
be++;
}
for(int i = be ; str[i] ; i ++)
{
if(ans>INT_MAX){
return flag==-1?INT_MIN:INT_MAX;
}
if(str[i]<='9' && str[i]>='0')
{
ans *= 10;
ans += str[i] - '0';
}
else{
break;
}
}
if(-ans == INT_MIN && flag == -1)return INT_MIN;
if(ans > INT_MAX)
{
return flag==-1?INT_MIN:INT_MAX;
}else{
return ans*flag;
}
}