two javascript solution 116ms


  • 0
    H

    solution 1: 116ms

    var isPalindrome = function(s) {
        var reg = /[\W_]/g;
        s = s.toLowerCase().replace(reg,'');
        var len = s.length;
        for(var i = 0; i < len/2;i++){
            if(s[i] !== s[len-i-1]) return false;
        }
        return true;
    };
    

    solution 2: 139ms

    var isPalindrome = function(s) {
        s = s.toLowerCase().replace(/[\W_]/g,'');
        var reverse = s.split('').reverse().join('');
        return s === reverse;
    };
    

Log in to reply
 

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