I'm trying to get palindrome using recursion like this, but I found that very costly because It's create new string when I use substring()
method, like in my code:
public static boolean isPalindrome(String s) {
if (s.length() <= 1)
return true;
else if (s.charAt(0) != s.charAt(s.length() - 1))
return false;
else return isPalindrome(s.substring(1, s.length() - 1));
}
Is there an alternative way to make it more efficient?