题意:判断一个字符串除掉空格和标点符号忽略大小写后是否是回文串。
题解:先把标点去掉,把字母统一变成小写,然后两头往中间判断回文。
class Solution {
public:
bool check(char s)
{
if(isalpha(s) || isdigit(s)) return true;
else return false;
}
bool isPalindrome(string s) {
int n = s.length();
string ss;
for(int i = 0; i < n; i++)
if(check(s[i])) ss += s[i];
n = ss.length();
if(n == 0) return true;
for(int i = 0 ,j = n - 1; i < n - 1; i++,j--)
{
if(tolower(ss[i]) != tolower(ss[j])) return false;
else continue;
}
return true;
}
};