class Solution {
public:
int atoi(const char str) {
//return atoi(str);
long ans=0;
//如果为换行符则直接置零
if(
str=='\0') return 0;
//取出字符前端为空格的部分
while(str==' ') str++;
//判别±
int sig=1;
if(
str=='+'){
sig=1;
str++;
}
if(str=='-')
{
sig=-1;
str++;
}
//进行实际计算
while(isdigit(
str))
{
ans=ans10+(str-'0');
str++;
//防止数值越界
if(anssig>=INT_MAX) return INT_MAX;
if(ans
sig<=INT_MIN) return INT_MIN;
}
return ans*sig;
}
};