Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0f13529

Browse files
committed
Added Redistribute Characters to Make All Strings Equal.java
1 parent 164d542 commit 0f13529

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public boolean makeEqual(String[] words) {
3+
return Arrays.stream(words)
4+
.reduce((a, b) -> a + b).orElse("") // Merge all strings
5+
.chars().mapToObj(c -> (char) c)
6+
.collect(Collectors.groupingBy(Function.identity(), HashMap::new, Collectors.counting())) // Build a frequency map
7+
.values().stream()
8+
.allMatch(v -> v % words.length == 0); // Predicate logic to check frequency of each character
9+
}
10+
}

0 commit comments

Comments
 (0)