# 验证回文串

给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。

说明:本题中,我们将空字符串定义为有效的回文串。

 

示例 1:

输入: "A man, a plan, a canal: Panama"
输出: true
解释:"amanaplanacanalpanama" 是回文串

示例 2:

输入: "race a car"
输出: false
解释:"raceacar" 不是回文串

 

提示:

## template ```cpp #include using namespace std; class Solution { public: bool isPalindrome(string s) { int left = 0, right; if ((right = s.size()) == 0) { return true; } while (left < right) { while (left < right && !isalnum(s[left])) { left++; } while (left < right && !isalnum(s[right])) { right--; } if (left < right) { if (tolower(s[left]) != tolower(s[right])) { return false; } } left++; right--; } return true; } }; ``` ## 答案 ```cpp ``` ## 选项 ### A ```cpp ``` ### B ```cpp ``` ### C ```cpp ```