public static void main(String[] args) {
String str = "aaaabbaaaabb";
char[] chars = str.toCharArray();
int i = 0;
int j = 1;
int tmp=chars.length;
while (j < chars.length) {
while (j<chars.length && chars[i] != chars[j]) {
j++;
}
tmp = j;
while (j < chars.length && chars[i] == chars[j]) {
i ++;
j++;
}
if (j != chars.length) {
i=0;
j=tmp + 1;
}
}
System.out.println(str.substring(0,tmp));
}
最直白的解法