62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
System.out.println(doCount("aadsaccdc"));
}
public static List<Character> doCount(String string){
List<Character> chars = new ArrayList<Character>();
char[] cs = string.toCharArray();
int max = 0;
List<Character> find = new ArrayList<Character>();
for(char c : cs){
int count = 0;
boolean isFind = false;
for(Character fc : find){
if(c == fc.charValue()){
isFind = true;
break;
}
}
if(!isFind){
find.add(c);
Matcher m = Pattern.compile(String.valueOf(c)).matcher(string);
while(m.find()){
count++;
}
if(count == max){
chars.add(c);
}else if(count > max){
max = count;
chars.clear();
chars.add(c);
}
}
}
return chars;
}