标签:
跳过所有非数字和字母,字母不分大小写
空串是对称的
class Solution {
public:
bool isPalindrome(string s) {
if (s.empty())
{
return true;
}
int head = 0,tail=s.size()-1;
while (head < tail)
{
if (isalnum(s[head]) && isalnum(s[tail]))
{
if (tolower(s[head]) == tolower(s[tail]))
{
head++; tail--;
}
else
{
return false;
}
}
if (!isalnum(s[head]))
{
head++;
}
if (!isalnum(s[tail]))
{
tail--;
}
}
return true;
}
};
标签:
原文地址:http://www.cnblogs.com/flyjameschen/p/4341950.html