C++ two-pointer solution.


  • 6
    C
    bool isPalindrome(string s) {
        int l=0, r=s.size()-1;
        while (l<r) {
            while (l<r && !isalnum(s[l]))
                l++;
            while (l<r && !isalnum(s[r]))
                r--;
            if (tolower(s[l])!=tolower(s[r]))
                return false;
            l++;
            r--;
        }
        return true;
    }

Log in to reply
 

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