File tree Expand file tree Collapse file tree 1 file changed +5
-10
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +5
-10
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- import java .util .HashSet ;
4
- import java .util .Set ;
3
+ import java .util .Arrays ;
4
+ import java .util .stream . Collectors ;
5
5
6
6
public class _1941 {
7
7
public static class Solution {
8
8
public boolean areOccurrencesEqual (String s ) {
9
9
int [] counts = new int [26 ];
10
- for (char c : s .toCharArray ()) {
10
+ char [] charArray = s .toCharArray ();
11
+ for (char c : charArray ) {
11
12
counts [c - 'a' ]++;
12
13
}
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 ;
14
+ return Arrays .stream (counts ).filter (i -> i != 0 ).boxed ().collect (Collectors .toSet ()).size () == 1 ;
20
15
}
21
16
}
22
17
}
You can’t perform that action at this time.
0 commit comments