125. Valid Palindrome

202408301019
tags: #two-pointers

const isAlphanumeric = (c) => c.match(/^[0-9a-zA-Z]+$/)

var isPalindrome = function(s) {
	let start = 0, end = s.length - 1;
	while (start <= end) {
		while (start < end && !isAlphanumeric(s[start])) {
			start += 1;
		}
		while (start < end && !isAlphanumeric(s[end])) {
			end -= 1;
		}
		if (start > end || s[start].toLowerCase() !== s[end].toLowerCase()) {
			return false;
		}
		start += 1;
		end -= 1;
	}
	return true;
};

Reference

https://leetcode.com/problems/valid-palindrome