7 lines C++


  • 0
    class Solution {
    public:
        bool isPalindrome(string s) {
            int i = 0, j = s.size() - 1;
            while(i < j){
                while(i < j && !isalnum(s[i])) i++;
                while(i < j && !isalnum(s[j])) j--;
                if(tolower(s[i++]) != tolower(s[j--])) return false;
            }
            return true;
        }
    };
    

Log in to reply
 

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