C++ 9ms easy to understand two-pointer solution


  • 0
    B
    bool isCharacter(char c){
            return (c >64 && c<91) ||(c > 96 && c< 123)||(c>47 && c<58);
        }
        bool isPalindrome(string s) {
            int i = 0, j= s.size()-1;
            while(i<j){
                if(!isCharacter(s[i]))
                    i++;
                else if(!isCharacter(s[j]))
                    j--;
                else if (tolower(s[i++])!=tolower(s[j--]))
                    return false;
            }
            return true;
        }
    

    I found this solution is easy to come up with.


Log in to reply
 

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