Skip to content

Commit 98b1552

Browse files
committed
Runtime: 0 ms (Top 100.0%) | Memory: 2.10 MB (Top 53.33%)
1 parent abc9d3b commit 98b1552

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Runtime: 0 ms (Top 100.0%) | Memory: 2.10 MB (Top 53.33%)
2+
3+
impl Solution {
4+
pub fn max_number_of_balloons(text: String) -> i32 {
5+
use std::collections::HashMap;
6+
7+
let mut counter: HashMap<char, i32> = "balloon".chars().map(|c| (c, 0)).collect();
8+
9+
text.chars().for_each(|c| {
10+
counter.entry(c).and_modify(|e| *e += 1);
11+
});
12+
13+
counter
14+
.iter()
15+
.map(|(&c, &num)| num / if "lo".contains(c) { 2 } else { 1 })
16+
.min()
17+
.unwrap()
18+
}
19+
}

0 commit comments

Comments
 (0)