Title:
Given a string, verify that it is a palindrome string, consider only the alphabetic and numeric characters, can ignore letter case.
Description: In this problem, we define the empty string as a valid palindromic sequence.
Example 1:
Input: "A man, a plan, a canal: Panama"
Output: true
Example 2:
Input: "race a car"
Output: false
public class LeetCode125a {
public boolean isPalindrome(String s) {
if(s.length() == 0)
return true;
int l=0,r=s.length()-1;
while(l<r){
if(!Character.isLetterOrDigit(s.charAt(l))){
l++;
}else if(!Character.isLetterOrDigit(s.charAt(r))){
r--;
}else{
if(Character.toLowerCase(s.charAt(l)) != Character.toLowerCase(s.charAt(r)))
return false;
l++;
r--;
}
}
return true;
}
}