递归实现检查字符串是否为回文串,忽略大小写及标点符号(包括空格)
public static boolean isPalindromes(String str){
return isPalindromes(str.toLowerCase().toCharArray(), 0, str.length()-1);
}
private static boolean isPalindromes(char[] charArray, int low, int high){
while(!Character.isLetter(charArray[low]))
low++;
while(!Character.isLetter(charArray[high]))
high--;
if(charArray[low] != charArray[high]) return false;
if(low == high || low == high - 1) return true;
return isPalindromes(charArray, low+1, high-1);
}