题意:将一个字符串转成整形
class Solution {
public:
int myAtoi(string str) {
long long ans=0;
int s=0,flag=1;
while(str[s]==' ')s++;
if(str[s]=='+'||str[s]=='-')
flag=(str[s++]=='+'?1:-1);
while(s<str.size()&&str[s]>='0'&&str[s]<='9')
{
ans=ans*10+str[s++]-'0';
if(ans*flag>INT_MAX)return INT_MAX;
if(ans*flag<INT_MIN)return INT_MIN;
}
return ans*flag;
}
};