Open msbazzik opened 1 year ago
Which language code has this issue?
Hi there, thank you for getting back. Here is the code:
public boolean isPalindrome(String s) {
int i = 0;
int j = s.length() - 1;
while (i < j) {
Character start = s.charAt(i);
Character end = s.charAt(j);
if (!Character.isLetterOrDigit(start)) {
i++;
continue;
}
if (!Character.isLetterOrDigit(end)) {
j--;
continue;
}
if (Character.toLowerCase(start) != Character.toLowerCase(end)) {
return false;
}
i++;
j--;
}
return true;
} Both strings of "" (empty) and " " (whitespace) are palindromes according to solution from the neetcode.
which language though? Java?
Hi, oh yes, I forgot to mention that it's Java, sorry
Not fully agree, that String of " "(whitespace) is palindrome, as it doesn't contain any characters after trimming. In other words, the Strings "" and " "(which is actually "" after removing all non-alphanumeric characters ) should return false.