Skip to content

Bug Report for is-palindrome #4783

@nallasrinivas678

Description

@nallasrinivas678

Bug Report for https://neetcode.io/problems/is-palindrome

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
we need to skip the while loop if its non alphanumeric we are missing continue statement.

here is the correct version:

class Solution {
    /**
     * @param {string} s
     * @return {boolean}
     */
    isPalindrome(s) {
        let left = 0;
        let right = s.length - 1;
        while(left < right){
            if(!this.isAlphaNumeric(s[left])){
                left++;
                continue;
            }
            if(!this.isAlphaNumeric(s[right])){
                right --;
                continue;
            }

            if(s[left].toLowerCase() !== s[right].toLowerCase()){
                return false;
            } 
            left++;
            right--;
        }
        return true;
    }

    isAlphaNumeric(char){
        return (char >= 'A' && char <= 'Z') ||
        (char >= 'a' && char <= 'z') ||
        (char >= '0' && char <= '9');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions