1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Solution { public boolean areOccurrencesEqual(String s) { int[] countMap = new int[26];
for (int i = 0; i < s.length(); i++) { countMap[s.charAt(i) - 'a']++; }
int exceptedCount = countMap[s.charAt(0) - 'a']; for (int count : countMap) { if (count != 0 && count != exceptedCount) { return false; } }
return true; } }
|
References
1941. Check if All Characters Have Equal Number of Occurrences