I have made the following code for the above program. In this program the test case "race a car" is not passing i.e. not showing the correct output for this test case. I don't know why. What's the reason? also if there is any way to correct this.
class Solution {
public boolean isPalindrome(String s) {
int f = 0, l = s.length() - 1;
s = s.toLowerCase();
while (f <= l) {
char char1 = s.charAt(f);
char char2 = s.charAt(l);
if (!(char1 >= 'a' && char1 <= 'z')) {
f++;
} else if (!(char2 >= 'a' && char2 <= 'z')) {
l--;
} else if (!(Character.isDigit(char1))) {
f++;
} else if (!(Character.isDigit(char2))) {
l--;
} else if (char1 == char2) {
f++;
l--;
} else
return false;
}
return true;
}
}