题目大意:判断字符串是否为回文,大小写不敏感,非数字或字母字符可以忽略
"A man, a plan, a canal: Panama"
is a palindrome.
"race a car"
is not a palindrome.
AC代码如下
class Solution {
public:
bool isPalindrome(string s) {
int len= s.length();
int low=0,high=len-1;
while(low<high)
{
while(low<len && !isalnum(s[low]))low++;
while(high>=0 && !isalnum(s[high]))high--;
if(low>=high)return true;
if(tolower(s[low])!=tolower(s[high]))return false;
low++;high--;
};
return true;
}
};