遇到3个一样的就标记
public static void test(String s) {
boolean modify = false;
int len = 0;
char[] re = new char[s.length()];
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) != '*') {
re[len++] = s.charAt(i);
}
}
char[] res = new char[len];
System.arraycopy(re, 0, res, 0, len);
char slow = 0;
char fast = 1;
while (fast < len) {
if (fast + 1 < len && res[fast] == res[fast + 1] && res[fast] == res[slow]) {
char temp = res[slow];
while (fast < len && res[fast] == temp) {
modify = true;
res[slow] = '*';
res[fast] = '*';
fast++;
}
}
slow = fast;
fast++;
}
if (modify) {
test(new String(res));
} else
System.out.println(Arrays.toString(res));
}