Mam im unable to understand the recursive Call.Can u please explain me with the code.
Recursive Call In Palindrome
- If there is only one character in string return true.
- Else compare first and last characters and recur for remaining substring.
see this:
static boolean isPalRec(String str,
int s, int e)
{
// If there is only one character
if (s == e)
return true;
// If first and last
// characters do not match
if ((str.charAt(s)) != (str.charAt(e)))
return false;
// If there are more than
// two characters, check if
// middle substring is also
// palindrome or not.
if (s < e + 1)
return isPalRec(str, s + 1, e - 1);
return true;
}