8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1be6ce0 commit b99ecdfCopy full SHA for b99ecdf
src/main/java/com/fishercoder/solutions/_1941.java
@@ -1,22 +1,17 @@
1
package com.fishercoder.solutions;
2
3
-import java.util.HashSet;
4
-import java.util.Set;
+import java.util.Arrays;
+import java.util.stream.Collectors;
5
6
public class _1941 {
7
public static class Solution {
8
public boolean areOccurrencesEqual(String s) {
9
int[] counts = new int[26];
10
- for (char c : s.toCharArray()) {
+ char[] charArray = s.toCharArray();
11
+ for (char c : charArray) {
12
counts[c - 'a']++;
13
}
- Set<Integer> set = new HashSet<>();
14
- for (int i : counts) {
15
- if (i != 0) {
16
- set.add(i);
17
- }
18
19
- return set.size() == 1;
+ return Arrays.stream(counts).filter(i -> i != 0).boxed().collect(Collectors.toSet()).size() == 1;
20
21
22
0 commit comments