//variables
int length = 0;
int greatestOddFreaquency = 0;
TreeMap tm = new TreeMap();
//lenght 1
if (s.length() == 1) {
return 1;
}
for (int i = 0; i < s.length(); i++) {
int total = 0; //to count how many times a charcter occurs
for (int j = 0; j < s.length(); j++) {
if (s.charAt(i) == s.charAt(j)) {
total++;
}
}
if (total % 2 != 0 && total >= greatestOddFreaquency) {
greatestOddFreaquency = total;
} else if (total % 2 == 0) {
tm.put(s.charAt(i), total);
}
}
for (Map.Entry entry : tm.entrySet()) {
length += entry.getValue();
//System.out.println("Key " + entry.getKey() + " val " +entry.getValue());
}
return length+=greatestOddFreaquency;
}
< /code>
Тем не менее, при запуске этого на чрезвычайно длинной строке мой код не удается. Любая помощь будет высоко оценена
Подробнее здесь: https://stackoverflow.com/questions/794 ... ng-strings