package leetcode;

/**
 * https://leetcode.com/problems/reorganize-string/
 */
public class Problem767 {
    public String reorganizeString(String S) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem767 prob = new Problem767();
        System.out.println(prob.reorganizeString("aab")); // aba
        System.out.println(prob.reorganizeString("aaab")); //
        System.out.println(prob.reorganizeString("aaabb")); // ababa
        System.out.println(prob.reorganizeString("babab")); // ababa
    }
}

@@ -12,16 +12,42 @@
 tcode;%0A%0A
+import java.util.Arrays;%0A%0A
 /**%0A * h
@@ -183,36 +183,1394 @@
     
-// TODO%0A        return null;
+CharCount%5B%5D array = new CharCount%5B26%5D;%0A        for (char i = 0; i %3C array.length; i++) %7B%0A            array%5Bi%5D = new CharCount((char) (i + 'a'), 0);%0A        %7D%0A        for (int i = 0; i %3C S.length(); i++) %7B%0A            array%5BS.charAt(i) - 'a'%5D.count++;%0A        %7D%0A        Arrays.sort(array, (a, b) -%3E Integer.compare(b.count, a.count));%0A        StringBuilder newString = new StringBuilder();%0A        for (int i = 0; i %3C array.length; i++) %7B%0A            for (int j = 0; j %3C array%5Bi%5D.count; j++) %7B%0A                newString.append(array%5Bi%5D.ch);%0A            %7D%0A        %7D%0A        StringBuilder sb = new StringBuilder();%0A        int i = 0;%0A        int j = 0;%0A        char%5B%5D chars = newString.toString().toCharArray();%0A        while (j %3C chars.length) %7B%0A            if (chars%5Bi%5D == chars%5Bj%5D) %7B%0A                j++;%0A            %7D else %7B%0A                sb.append(chars%5Bi++%5D).append(chars%5Bj++%5D);%0A            %7D%0A        %7D%0A//        sb.append(chars%5Bi%5D);%0A//        if (i + 1 %3C S.length() && chars%5Bi%5D == chars%5Bi + 1%5D) %7B%0A//            return %22%22;%0A//        %7D%0A        return sb.toString();%0A    %7D%0A%0A    private static class CharCount %7B%0A        private char ch;%0A        private int count;%0A%0A        public CharCount(char ch, int count) %7B%0A            this.ch = ch;%0A            this.count = count;%0A        %7D%0A%0A        @Override%0A        public String toString() %7B%0A            return ch + %22 --%3E %22 + count;%0A        %7D
 %0A   
@@ -1658,24 +1658,26 @@
 oblem767();%0A
+//
         Syst
@@ -1725,24 +1725,26 @@
 %22)); // aba%0A
+//
         Syst
@@ -1793,16 +1793,18 @@
 %22)); //%0A
+//
         
@@ -1914,20 +1914,92 @@
 String(%22
-baba
+aabbb%22)); // babab%0A//        System.out.println(prob.reorganizeString(%22aaabb
 b%22)); //
@@ -2000,21 +2000,22 @@
 )); // ababa
+b
 %0A    %7D%0A%7D%0A

Update problem 767