**Input:** s = "A man, a plan, a canal: Panama"
**Output:** true
**Explanation:** "amanaplanacanalpanama" is a palindrome.
**Input:** s = "race a car"
**Output:** false
**Explanation:** "raceacar" is not a palindrome.
class Solution {
public boolean isPalindrome(String s) {
// input check and edge cases
if (s == null) return false;
if (s.length() <= 1) return true;
// 2 pointers
s = s.toLowerCase();
int l = 0, r = s.length() - 1;
while (l < r) {
while (l < r && !valid(s.charAt(l)) ) l++;
while (l < r && !valid(s.charAt(r)) ) r--;
if (s.charAt(l) != s.charAt(r)) return false;
l++;
r--;
}
return true;
}
private boolean valid(char c) {
if (c >= 'a' && c <= 'z'
|| c >= '0' && c <= '9') {
return true;
}
return false;
}
}