A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.
Given a string s, return trueif it is a palindrome, orfalse
1 2 3 4 5 6 7 8 9 10 11 12 13 14
classSolution { public: boolisPalindrome(string s){ string res = ""; for(auto ch : s) { if(isalpha(ch)) res.push_back(::tolower(ch)); elseif(isdigit(ch)) res.push_back(ch); } for(int l = 0, r = res.size() - 1; l < r; l += 1, r -= 1) { if(res[l] != res[r]) returnfalse; } returntrue; } };