Simple JavaScript solution


  • 0
    var isPalindrome = function(s) {
        s = s.replace(/[^a-z0-9]/gi,'').toLowerCase();
        let n = s.length;
    
        for(let i = 0; i <= n/2; i++){
            if(s[i] !== s[n-i-1]){
                return false;
            }
        }
        return true;
    };
    

Log in to reply
 

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