Simple to Understand Solution C++


  • 0
    F
        bool isPalindrome(string s) {
            int left = 0, right = (int)s.size() - 1;
            while (left < right) {
                while (left < right && !isalnum(s[left])) ++left;
                while (right > left && !isalnum(s[right])) --right;
                if (left < right && tolower(s[left++]) != tolower(s[right--])) 
                    return false;
            }
            return true;
        }
    

Log in to reply
 

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