题目描述
blablabla
样例
blablabla
算法1
class Solution {
public:
int strToInt(string str) {
long long res=0;
bool isneg=false;
int i=0,j=str.size();
while (i<j && str[i]==' ') i++;
if (str[i]=='-') i++,isneg=true;
else if (str[i]=='+') i++;
else if (!(str[i]>='0' && str[i]<='9')) return 0;
for (;i<j && str[i]>=0 && str[i]<='9';i++) {
if (isneg) res=res*10-(str[i]-'0');
else res=res*10+str[i]-'0';
}
if (res>INT_MAX) res=INT_MAX;
else if (res<INT_MIN) res=INT_MIN;
return res;
}
};