diff --git a/rs/minimum-number-of-steps-to-make-two-strings-anagram.rs b/rs/minimum-number-of-steps-to-make-two-strings-anagram.rs new file mode 100644 index 0000000..6563b16 --- /dev/null +++ b/rs/minimum-number-of-steps-to-make-two-strings-anagram.rs @@ -0,0 +1,20 @@ +use std::cmp; +use std::collections::HashMap; + +impl Solution { + pub fn min_steps(s: String, t: String) -> i32 { + let mut counters: HashMap = HashMap::new(); + + // needed + for c in s.chars() { + *counters.entry(c).or_insert(0) += 1; + } + + // found + for c in t.chars() { + *counters.entry(c).or_insert(0) -= 1; + } + + counters.values().map(|count| cmp::max(0, *count)).sum() + } +}