Easy C++ Solution|| O(n) time O(1) space


#1
int Solution::atoi(const string s) {
    int st=0;
        int sign=0;
        while(s[st]==' ')st++;
        if(s[st]=='-' || s[st]=='+' )
        {
            if(s[st]=='-')sign++;
            st++;
        }
    
      long long  int n=0;
        for(int i=st;i<s.length();i++)
        {
            
            if(s[i]>='0' && s[i]<='9')
            {
                //cout<<1<<endl;
                int k=s[i]-'0';
                if(n*10+k>INT_MAX)
                {
                    n= sign? INT_MIN : INT_MAX;
                    return n;
                }
                n=n*10+k;
        
            }
            else break;
        }
           n= sign? -n : n;
        return n;
        
}