1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | class Solution { public: string convert(string s) { string ret = ""; for (auto &c : s) if (isalpha(c) || isdigit(c)) ret += tolower(c); return ret; } bool isPalindrome(string s) { s = convert(s); int len = s.length(); for (int i = 0; i < len; i++) if (s[i] != s[len - i - 1]) return false; return true; } }; |