package leetcode;

/**
 * https://leetcode.com/problems/break-a-palindrome/
 */
public class Problem1328 {
    public String breakPalindrome(String palindrome) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1328 prob = new Problem1328();
        System.out.println(prob.breakPalindrome("abccba")); // "aaccba"
        System.out.println(prob.breakPalindrome("a")); // ""
        System.out.println(prob.breakPalindrome("aba")); // "abb"
        System.out.println(prob.breakPalindrome("bab")); // "aab"
    }
}

@@ -167,16 +167,73 @@
     
-// TODO%0A
+if (!isPalindrome(palindrome) %7C%7C palindrome.length() == 1) %7B%0A    
     
@@ -247,376 +247,1082 @@
 urn 
-null
+%22%22
 ;%0A    
-%7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1328 prob = new Problem1328();%0A        System.out.println(prob.breakPalindrome(%22abccba%22)); // %22aaccba%22%0A        System.out.println(prob.breakPalindrome(%22a%22)); // %22%22%0A        System.out.println(prob.breakPalindrome(%22aba%22)); // %22abb%22%0A        System.out.println(prob.breakPalindrome(%22bab%22)); // %22aab%22
+    %7D%0A        char%5B%5D answer = palindrome.toCharArray();%0A        boolean replaced = false;%0A        for (int i = 0; i %3C palindrome.length(); i++) %7B%0A            if (palindrome.length() %25 2 != 0) %7B%0A                int mid = palindrome.length() / 2;%0A                if (palindrome.charAt(i) != 'a' && i != mid) %7B%0A                    answer%5Bi%5D = 'a';%0A                    replaced = true;%0A                    break;%0A                %7D%0A            %7D else %7B%0A                if (palindrome.charAt(i) != 'a') %7B%0A                    answer%5Bi%5D = 'a';%0A                    replaced = true;%0A                    break;%0A                %7D%0A            %7D%0A        %7D%0A        if (!replaced) %7B%0A            answer%5Banswer.length - 1%5D = (char) (answer%5Banswer.length - 1%5D + 1); // must be the last one%0A        %7D%0A        return new String(answer);%0A    %7D%0A%0A    private static boolean isPalindrome(String str) %7B%0A        for (int i = 0, j = str.length() - 1; i %3C j; i++, j--) %7B%0A            if (str.charAt(i) != str.charAt(j)) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return true;
 %0A   

Solve problem 1328