/**
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function (s) {
let leftIndex = 0,
rightIndex = s.length - 1;
while (leftIndex < rightIndex) {
while (leftIndex < rightIndex && !isValidCharacter(s[leftIndex])) {
++leftIndex;
}
while (leftIndex < rightIndex && !isValidCharacter(s[rightIndex])) {
--rightIndex;
}
if (leftIndex >= rightIndex) {
break;
}
if (s[leftIndex].toLowerCase() !== s[rightIndex].toLowerCase()) {
return false;
}
++leftIndex;
--rightIndex;
}
return true;
};
function isValidCharacter(ch) {
return (ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
(ch >= '0' && ch <= '9');
}