class Solution {
public:
bool isPalindrome(string s) {
if (s.length() <= 1)
return true;
int last = s.length() - 1;
int first = 0;
// 先统一转化为小写
for(int i = 0; i < s.length(); ++i)
s[i] = tolower(s[i]);
while(first <= last){
// 忽略不是字母或数字的字符
while(!isalnum(s[first]) && first <= last) ++first;
while(!isalnum(s[last]) && first <= last) --last;
if (first > last)
return true;
if (s[first] != s[last])
return false;
++first,--last;
}
return true;
}
};
static int x=[](){
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return 0;
}();