Redistribute Characters to Make All Strings Equal
给一个string的数组, 求里面的数字是否能通过移动字符, 变成同一个string.
这题就是统计一下所有的字符, 然后对字符串组长度做整除, 看看是不是能整除.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
class Solution { public boolean makeEqual(String[] words) { int[] count = new int[26]; for(String w : words) for(char c : w.toCharArray()){ count[c - 'a']++; } for(int i = 0; i < 26; i++) if(count[i] % words.length != 0) return false; return true; } } |