Simplest C++ Solution


  • 0
    M
    class Solution {
    public:
        bool isPalindrome(string s) {
            string r1, r2;
            for (char c: s) if (isalnum(c)) r1.append(1, tolower(c));
            r2 = r1;
            reverse(r2.begin(), r2.end());
            return r1 == r2;
        }
    };
    

Log in to reply
 

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