Ignoring case and non-alphanumeric characters, return true if s reads the same forward and backward.
Move lo and hi toward each other, skipping non-alphanumeric characters, and compare lowercase characters.
1function isPalindrome(s: string): boolean {2let lo = 0, hi = s.length - 1;3while (lo < hi) {4if (!/[a-z0-9]/i.test(s[lo])) { lo++; continue; }5if (!/[a-z0-9]/i.test(s[hi])) { hi--; continue; }6if (s[lo].toLowerCase() !== s[hi].toLowerCase()) return false;7lo++; hi--;8}9return true;10}
Pointers at both ends.
Space: play/pause · ←/→: step