JPHamlett
2011-03-15 10:57:54
Ok, so I've been staring at this code for a while and I just can not understand how it does it.
Now I understand what it does, I just don't understand how it does it. If someone would be kind enough to explain this code to me I'd be very appreciative.
[RIGHT]~JP[/RIGHT]
public static boolean isPalindrome(String s)
{
if (s.length() <= 1)
return true; // Base case
else
{
if (s.charAt(0) == s.charAt(s.length() - 1))
return isPalindrome(s.substring(1, s.length() - 1 ) );
else
return false;
}
}
Now I understand what it does, I just don't understand how it does it. If someone would be kind enough to explain this code to me I'd be very appreciative.
[RIGHT]~JP[/RIGHT]