/*判断一行字符串是否是回文。只考虑数字和字母(only alphanumeric),忽略大小写。例子如下:
"A man, a plan, a canal: Panama"
is a palindrome.
public class ValidPalindrome {
public static void main(String[] args) {
// TODO Auto-generated method stub
ValidPalindrome validPalindrome=new ValidPalindrome();
System.out.println(validPalindrome.isPalindrome("A man, a plan, a canal: Panama"));
}
public boolean isPalindrome(String s) {
int i=0,j=s.length()-1;
while(i<j){
if(!Character.isLetterOrDigit(s.charAt(i))){//如果拿到的在i处不是字母也不是数字,那么
i++;continue;
}
if(!Character.isLetterOrDigit(s.charAt(j))){
j--;continue;
}
if(Character.toLowerCase(s.charAt(i))!=Character.toLowerCase(s.charAt(j)))
return false;
i++;j--;
}
return true;
}
}