3мс
Код: Выделить всё
// Update the count array by intersecting with each subsequent word
for (int i = 1; i < words.length; i++) {
int[] t = new int[26];
for (char c : words[i].toCharArray()) {
t[c - 'a']++;
}
last = intersection(last, t);
}
1 мс
Код: Выделить всё
// Update the count array by intersecting with each subsequent word
for (int i = 1; i < words.length; i++) {
last = intersection(last, count(words[i]));
}
private int[] count(String str) {
int[] t = new int[26];
for (char c : str.toCharArray()) {
t[c - 'a']++;
}
return t;
}
Почему в отдельной вспомогательной функции он работает быстрее?< /п>
Подробнее здесь: https://stackoverflow.com/questions/787 ... r-function
Мобильная версия