7 lines concise and easy understand c++ solution


  • 3
    A
    class Solution {
    public:
        bool isPalindrome(string s) {
            int l = 0, r = s.size() - 1;
            while(l <= r){
                while(!isalnum(s[l]) && l < r) l++;
                while(!isalnum(s[r]) && l < r) r--;
                if(toupper(s[l]) != toupper(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.