Two pointers skip non-alphanumeric characters and compare case-insensitively.
function isPalindrome(s): left = 0 right = len(s) - 1 while left < right: while left < right and not isAlphanumeric(s[left]): left += 1 while left < right and not isAlphanumeric(s[right]): right -= 1 if toLower(s[left]) != toLower(s[right]): return false left += 1 right -= 1 return true
time, space.