class Solution {
public:
bool check(char c)
{
if(c=='+') return true;
if(c=='-') return true;
if(c>='0'&&c<='9') return true;
return false;
}
int strToInt(string str) {
long long res=0;
int i=0;
bool flag=false;
while(str[i]==' ') i++;
if(!check(str[i])) return 0;
if(str[i]=='-'||str[i]=='+')
{
if(str[i]=='-') flag=true;
i++;
}
while(i < str.size()&&check(str[i]))
{
res=res*10+(str[i]-'0');
if(res>INT_MAX)
{
if(flag) return INT_MIN;
else return INT_MAX;
}
i++;
}
if(flag) res=-res;
return res;
}
};
标签:转换成,return,INT,MAX,整数,flag,res,字符串,true
From: https://www.cnblogs.com/tangxibomb/p/17413294.html