Can anyone help me ( code working well with custom inputs)


#1

int Solution::atoi(const string A) {
int res=0,sign=1,ans,k=0;
if(A[0]==’-’)sign=-1;
if(A[0]==’+’)sign=1;
for(int i=0;A[i]!=’\0’&&A[i]!=’ ';i++){
if(!(A[i]>=‘0’&&A[i]<=‘9’))continue;
res=res10+int(A[i]-‘0’);
if((!(A[i+1]>=‘0’&&A[i+1]<=‘9’))&&A[i+1]!=’\0’)break;
}
try{
ans=sign
res;
return ans;
}
catch(…){
return (sign=-1)?INT_MIN:INT_MAX;
}
}