java: add “1897. Redistribute Characters to Make All Strings Equal”

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2023-12-31 00:53:19 +01:00
parent ab78965115
commit 48847d9631
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,21 @@
class Solution {
public boolean makeEqual(String[] words) {
int[] counters = new int[26];
for (String w : words) {
for (int i = 0; i < w.length(); ++i) {
++counters[w.charAt(i) - 'a'];
}
}
int N = words.length;
for (int count : counters) {
if (count % N != 0) {
return false;
}
}
return true;
}
}