mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
21 lines
466 B
Rust
21 lines
466 B
Rust
|
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()
|
||
|
}
|
||
|
}
|