Minimum number of Appends needed to make a string palindrome | Java program to find minimum number of appends needed to make a string Palindrome ; Checking if the string is palindrome or not ; single character is always palindrome ; pointing to first character ; pointing to last character ; Recursive function to count number of appends ; Removing first character of string by incrementing base address pointer . ; Driver code
class GFG { static boolean isPalindrome ( char [ ] str ) { int len = str . length ; if ( len == 1 ) return true ; int ptr1 = 0 ; int ptr2 = len - 1 ; while ( ptr2 >= ptr1 ) { if ( str [ ptr1 ] != str [ ptr2 ] ) return false ; ptr1 ++ ; ptr2 -- ; } return true ; } static int noOfAppends ( String s ) { if ( isPalindrome ( s . toCharArray ( ) ) ) return 0 ; s = s . substring ( 1 ) ; return 1 + noOfAppends ( s ) ; } public static void main ( String arr [ ] ) { String s = " abede " ; System . out . printf ( "%dNEW_LINE", noOfAppends(s)); } }