-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
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
Labels
No labels