A palindrome is any word phrase or sentence that reads the s
Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
public class PalindromeRec {
public static boolean isPalindromeRec(String str){
// Base case
if(str == null || str.trim() == \"\")
return true;
return isPalindromeRecUtil(str, 0, str.length()-1);
}
public static boolean isPalindromeRecUtil(String str, int i, int j){
// Base case
if( i == j)
return true;
char ith = str.charAt(i);
char jth = str.charAt(j);
if(!Character.isLetter(ith) && !Character.isDigit(ith))
return isPalindromeRecUtil(str, i+1, j); // skip special characters
if(!Character.isLetter(jth) && !Character.isDigit(jth))
return isPalindromeRecUtil(str, i, j-1);// skip special characters
// if character is lette then converting in lower case
if(Character.isLetter(ith))
ith = Character.toLowerCase(ith);
if(Character.isLetter(jth))
jth = Character.toLowerCase(jth);
if(ith != jth)
return false;
return isPalindromeRecUtil(str, i+1, j-1);
}
public static void main(String[] args) {
System.out.println(isPalindromeRec(\"M a ,....dv... dam\"));
System.out.println(isPalindromeRec(\"M a ,....i... dam\"));
System.out.println(isPalindromeRec(\"A man, a Plan, a canal, panama\"));
}
}
/*
Sample run:
true
false
true
*/

