C++ 9ms two pointers


  • 0
    bool isPalindrome(string s) {
            transform(s.begin(),s.end(),s.begin(),::tolower);
            string::iterator head=s.begin();
            string::iterator tail=s.end()-1;
            while(head-tail<0){
                while(!isalnum(*head)) head++;
                while(!isalnum(*tail)) tail--;
                if(*head!=*tail&&head-tail<0) return false;
                head++;
                tail--;
            }
            return true;
        }
    

Log in to reply
 

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