Precise JavaScript code with 4 lines


  • 0
    V
    var isPalindrome = function(s) {
        if (!s) return true;
        var str = s.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
        var rev_str = str.split('').reverse().join('');
        return str === rev_str;
    };
    

Log in to reply
 

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