Javascript Solution | O(N)


  • 0
    var isPalindrome = function(s) {
        if (s) {
            // Remove special chars and white spaces
            s = s.replace(/[\W_]/g,'').toLowerCase();
    
            var start = 0;
            var end = s.length - 1;
    
            while (start < end) {
                if (s[start] !== s[end]) {
                    return false;
                }
                start++;
                end--;
            }
        }
        return true;      
    };

Log in to reply
 

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