Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 515 Bytes

File metadata and controls

20 lines (18 loc) · 515 Bytes

Two Pointer

Screen Shot 2023-02-20 at 11 16 38 AM

/**
 * @param {string} s
 * @return {boolean}
 */
var isPalindrome = function(s) {
    let str = s.replace(/[^0-9a-z]/gi, '').toLowerCase();
    let left = 0, right = str.length - 1;
    while(left < right) {
        if(str[left] !== str[right]) return false;
        left++;
        right--;
    }
    return true;
};