rs: add “1347. Minimum Number of Steps to Make Two Strings Anagram”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
fee07aaed3
commit
a1de882ad5
1 changed files with 20 additions and 0 deletions
20
rs/minimum-number-of-steps-to-make-two-strings-anagram.rs
Normal file
20
rs/minimum-number-of-steps-to-make-two-strings-anagram.rs
Normal file
|
@ -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<char, i32> = 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()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue