No libary function..implemented directly


  • 0
    L
      bool isPalindrome(string s) {
        
        int len=s.length();
        char l,r;
        const char *i = s.c_str(),*j=i+len-1;
        for( ; i < j ;)
        {
            if( !(*i >= 'A' && *i <= 'Z') && !(*i >= '0' && *i <= '9') && !(*i >= 'a' && *i <='z'))
                {i++; }
            else if( !(*j >= 'A' && *j <='Z') && !(*j >='0' && *j <= '9') && !(*j >= 'a' && *j <= 'z'))
                {j--;}
            else 
            {
                l=*i;
                r=*j;
                if ( (*j >= 'A' && *j <='Z') )
                    r = 'a' + *j -'A';
                if ( (*i >= 'A' && *i <='Z') )
                    l = 'a' + *i -'A';
                if( l != r  ) return false;
                i++;j--;
                 
            }
            
        }
        return true;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.