Javascript beats 91%


  • 0
    R

    I was forcecd to use regex in order to check the alphanumeric portion. Googling did not help find any alternatives, so please let me know if anyone finds any for Javascript:

    var isPalindrome = function(s) {
        
       
        s = s.replace(/[^0-9a-zA-Z]+/gmi,"");
        s = s.toLowerCase();
        var l = 0, r = s.length - 1;
        console.log(s);
    
        while(l<r) {
            if(s.charAt(l) != s.charAt(r)) {
                return false;
            }
            l++;
            r--;
        }
        return true;
    };
    

Log in to reply
 

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