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
class Solution {
public boolean isPalindrome(String s) {
if(s==null||s.length()==0){
return true;
}
String str = s.replaceAll("[^0-9a-zA-Z]", "").toLowerCase();;
int length=str.length();
for(int i=0,j=length-1;i<j;i++,j--){
if( str.charAt(i)!= str.charAt(j))
return false;
}
return true;
}
}