Maximum Number of Balloons LeetCode solution in Rust

1
impl Solution {
2
pub fn max_number_of_balloons(text: String) -> i32 {
3
use std::collections::HashMap;
4

5
let mut counter: HashMap<char, i32> = "balloon".chars().map(|c| (c, 0)).collect();
6

7
text.chars().for_each(|c| {
8
counter.entry(c).and_modify(|e| *e += 1);
9
});
10

11
counter
12
.iter()
13
.map(|(&c, &num)| num / if "lo".contains(c) { 2 } else { 1 })
14
.min()
15
.unwrap()
16
}
17
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0