Skip to content

Commit b99ecdf

Browse files
refactor 1941
1 parent 1be6ce0 commit b99ecdf

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
package com.fishercoder.solutions;
22

3-
import java.util.HashSet;
4-
import java.util.Set;
3+
import java.util.Arrays;
4+
import java.util.stream.Collectors;
55

66
public class _1941 {
77
public static class Solution {
88
public boolean areOccurrencesEqual(String s) {
99
int[] counts = new int[26];
10-
for (char c : s.toCharArray()) {
10+
char[] charArray = s.toCharArray();
11+
for (char c : charArray) {
1112
counts[c - 'a']++;
1213
}
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;
2015
}
2116
}
2217
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy