@@ -0,0 +1,1173 @@
+public class StringReorderDistantApart %7B%0A%0A%09/**%0A%09 * http://leetcode.com/2010/05/here-is-another-google-phone-interview.html%0A%09 */%0A%09public String reorderString(String source, int k) %7B%0A%09%09int%5B%5D freq = new int%5B256%5D;%0A%09%09for (Character c : source.toCharArray()) %7B%0A%09%09%09freq%5Bc%5D++;%0A%09%09%7D%0A%09%09int%5B%5D used = new int%5B256%5D;%0A%09%09String result = %22%22;%0A%09%09for (int i = 0; i %3C source.length(); i++) %7B%0A%09%09%09boolean%5B%5D excep = new boolean%5B256%5D;%0A%09%09%09boolean done = false;%0A%09%09%09while (!done) %7B%0A%09%09%09%09int j = findMaxFreq(freq, excep);%0A%09%09%09%09if (j == -1) %7B%0A%09%09%09%09%09return null;%0A%09%09%09%09%7D%0A%09%09%09%09excep%5Bj%5D = true;%0A%09%09%09%09if (used%5Bj%5D %3C= 0) %7B%0A%09%09%09%09%09used%5Bj%5D = k;%0A%09%09%09%09%09freq%5Bj%5D--;%0A%09%09%09%09%09result += (char) j;%0A%09%09%09%09%09done = true;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%09for (int j = 0; j %3C 256; j++) %7B%0A%09%09%09%09used%5Bj%5D--;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return result;%0A%09%7D%0A%0A%09private int findMaxFreq(int%5B%5D freq, boolean%5B%5D excep) %7B%0A%09%09int maxFreq = -1;%0A%09%09for (int i = 0; i %3C freq.length; i++) %7B%0A%09%09%09if (excep%5Bi%5D == false && freq%5Bi%5D %3E 0 && (maxFreq == -1 %7C%7C freq%5Bi%5D %3E freq%5BmaxFreq%5D)) %7B%0A%09%09%09%09maxFreq = i;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return maxFreq;%0A%09%7D%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09StringReorderDistantApart srda = new StringReorderDistantApart();%0A%0A%09%09System.out.println(srda.reorderString(%22aabbaa%22, 2));%0A%09%7D%0A%7D%0A

string reorder distant apart