C++中如何快速过滤?
bool isPalindrome(string s)
{
int size = 0;
for (int i = 0, j = 0; j < s.size(); j++)
{
if ((s[j] >= '0' && s[j] <= '9') || (s[j] >= 'a' && s[j] <= 'z') || (s[j] >= 'A' && s[j] <= 'Z'))
{
s[i++] = s[j];
}
size = i;
}
for (int i = 0; i < s.size(); i++)
{
if (s[i] >= 'A' && s[i] <= 'Z')
{
s[i] += 32;
}
}
int left = 0, right = size - 1;
while (left < right)
{
if (s[left] == s[right])
{
left++;
right--;
}
else
return false;
}
return true;
}