Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For
example,"A
man, a plan, a canal: Panama"
is a palindrome."race a
car"
is not a palindrome.
1 public class Solution { 2 public boolean isPalindrome(String s) { 3 if(s.length()<=1) return true; 4 s = s.toLowerCase(); 5 int start = 0; 6 int end = s.length()-1; 7 while(start<end){ 8 if(!is(s.charAt(start))) start++; 9 else if(!is(s.charAt(end))) end --; 10 else if(s.charAt(start)==s.charAt(end)){start++;end--;} 11 else break; 12 } 13 if(start>=end) return true; 14 else return false; 15 } 16 public boolean is(char a){ 17 if(a<=‘z‘&& a>=‘a‘ || a>=‘0‘&&a<=‘9‘){ 18 return true; 19 } 20 else return false; 21 } 22 }