Lintcode 415. Valid palindrome string
Title description: Given a string, judge whether it is a palindrome. Only letters and numbers are considered, and case is ignored.
class Solution {
public:
/**
* @param s: A string
* @return: Whether the string is a valid palindrome
*/
bool isPalindrome(string &s) {
for (int i = 0, j = s.size() - 1; i < j; ++i, --j) {
while (!isdigit(s[i]) && !isalpha(s[i]) && i < j) {
++i;
}
while (!isdigit(s[j]) && !isalpha(s[j]) && i < j) {
--j;
}
if (i < j && tolower(s[i]) != tolower(s[j])) {
return false;
}
}
return true;
}
};