My C++ Solution ...check it out


#1

int Solution::atoi(const string A)
{
int i=0;
while(A[i]==’ ‘) i++;
int sign=1;
if(A[i]==’-’ || A[i]==’+’)
{
sign = A[i++]==’-’? -1 : 1 ;
}
long long int res=0;
while(A[i]-‘0’>=0 && A[i]-‘0’<=9)
{
res=res10 + (A[i]-‘0’);
i++;
if((res
sign)>INT_MAX || (ressign)<INT_MIN)
{
if(sign==-1) return INT_MIN;
else return INT_MAX;
}
}
return int(sign
res);
}