@@ -0,0 +1,1248 @@
+/*%0AGiven a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.%0A%0AFor example:%0A%0AGiven %22aacecaaa%22, return %22aaacecaaa%22.%0A%0AGiven %22abcd%22, return %22dcbabcd%22.%0A*/%0Aimport java.util.*;%0A%0Apublic class ShortestPalindrome %7B%0A%09public static String shortestPalindrome(String s) %7B%0A        int adds = 0; %0A        if(s.length() %3C= 1) return s;%0A        int L = s.length();%0A        char%5B%5D sc = s.toCharArray();%0A        boolean pal = true;%0A        while(adds %3C L)%7B%0A            for(int i = 0; i %3C= (L - adds)/2; i++)%7B%0A                if(sc%5Bi%5D != sc%5BL-1-adds-i%5D)%7B%0A                    adds++;%0A                    pal = false;%0A                    break;%0A                %7D%0A            %7D%0A            if(pal == true)%7B%0A                String suffix = s.substring(L-adds);%0A                return new StringBuffer(suffix).reverse().toString() + s;%0A                %0A            %7D%0A            pal = true;%0A        %7D%0A        return s+s;%0A    %7D%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09String s = %22abcd%22;%0A%09%09String res = shortestPalindrome(s);%0A%09%09System.out.println(%22Source string: %22 + s);%0A%09%09System.out.println(%22Shortest pal string: %22 + res);%0A%09%09return;%0A%09%7D%09%0A%7D%0A

palindrome string - TLE