用双指针,left right从两头往中间对比,不是字母的都略过,比的时候化成小写字母
125. 验证回文串 - 力扣(LeetCode)
class Solution {
public:bool isPalindrome(string s) {if(s.size() <= 1)return true;int left = 0;int right = s.size() - 1;while(left < right){while(left < right && !isalnum(s[left])){left++;}while(left < right && !isalnum(s[right])){right--;}if(tolower(s[left]) != tolower(s[right]))return false;left++;right--;}return true;}
};