Short Solution in C++


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

Log in to reply
 

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