Skip to content

Commit e4b2a65

Browse files
committed
Create 1897-redistribute-characters-to-make-all-strings-equal.rs
1 parent 3380fca commit e4b2a65

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pub fn make_equal(words: Vec<String>) -> bool {
2+
let words_len = words.len();
3+
if words_len == 1 { return true }
4+
use std::collections::HashMap;
5+
let mut mmp = HashMap::new();
6+
for word in words {
7+
for c in word.chars().collect::<Vec<char>>() {
8+
let count = mmp.entry(c).or_insert(0);
9+
*count += 1;
10+
}
11+
}
12+
mmp.retain(|_, v| *v % words_len != 0);
13+
mmp.is_empty()
14+
}
15+
16+
fn main() {
17+
let words = ["abc","aabc","bc"].iter().map(|e|e.to_string()).collect::<Vec<String>>();
18+
println!("{:?}", make_equal(words));
19+
}

0 commit comments

Comments
 (0)