Skip to content

Commit ff84fb3

Browse files
committed
Create: 1189-maximum-number-of-balloons.rs
1 parent ee7a3bc commit ff84fb3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::collections::HashMap;
2+
3+
impl Solution {
4+
pub fn max_number_of_balloons(text: String) -> i32 {
5+
let mut count_text = HashMap::new();
6+
let mut balloon = HashMap::new();
7+
let mut result = text.len();
8+
9+
for ch in text.chars() {
10+
*count_text.entry(ch).or_insert(0) += 1;
11+
}
12+
13+
for ch in "balloon".chars() {
14+
*balloon.entry(ch).or_insert(0) += 1;
15+
}
16+
17+
for ch in balloon.keys() {
18+
result = result.min(count_text.get(ch).unwrap_or(&0) / balloon.get(ch).unwrap());
19+
}
20+
21+
result as i32
22+
}
23+
}

0 commit comments

Comments
 (0)