java: add “1897. Redistribute Characters to Make All Strings Equal”
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
ab78965115
commit
48847d9631
1 changed files with 21 additions and 0 deletions
21
java/redistribute-characters-to-make-all-strings-equal.java
Normal file
21
java/redistribute-characters-to-make-all-strings-equal.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue