Skip to content

Commit

Permalink
Create: 1189-maximum-number-of-balloons.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
AkifhanIlgaz committed Jan 4, 2023
1 parent ee7a3bc commit ff84fb3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rust/1189-maximum-number-of-balloons.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::collections::HashMap;

impl Solution {
pub fn max_number_of_balloons(text: String) -> i32 {
let mut count_text = HashMap::new();
let mut balloon = HashMap::new();
let mut result = text.len();

for ch in text.chars() {
*count_text.entry(ch).or_insert(0) += 1;
}

for ch in "balloon".chars() {
*balloon.entry(ch).or_insert(0) += 1;
}

for ch in balloon.keys() {
result = result.min(count_text.get(ch).unwrap_or(&0) / balloon.get(ch).unwrap());
}

result as i32
}
}

0 comments on commit ff84fb3

Please sign in to comment.