Short JavaScript Solution


  • 0
    T
    var isPalindrome = function (s) {
        var i = 0;
        var j = s.length - 1;
        var regex = /[a-z0-9]/i;
        while (i <= j) {
            if (!regex.test(s[i])) {
                i++;
            } else if (!regex.test(s[j])) {
                j--;
            } else if (s[i++].toLowerCase() !== s[j--].toLowerCase()) {
                return false;
            }
        }
        return true;
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.