This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaximum-number-of-balloons.rs
47 lines (42 loc) · 1.64 KB
/
maximum-number-of-balloons.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
struct Solution;
impl Solution {
pub fn max_number_of_balloons(text: String) -> i32 {
let mut b = 0;
let mut a = 0;
let mut ls = 0;
let mut os = 0;
let mut n = 0;
for i in text.chars() {
match i {
'b' => b += 1,
'a' => a += 1,
'l' => ls += 1,
'o' => os += 1,
'n' => n += 1,
_ => continue,
}
}
b.min(a).min(ls / 2).min(os / 2).min(n)
}
}
fn main() {
println!(
"{}",
Solution::max_number_of_balloons("nlaebolko".to_string())
);
}
#[cfg(test)]
mod tests {
use crate::Solution;
#[test]
fn testt_impl1() {
assert_eq!(Solution::max_number_of_balloons("nlaebolko".to_string()), 1);
assert_eq!(
Solution::max_number_of_balloons("loonbalxballpoon".to_string()),
2
);
assert_eq!(Solution::max_number_of_balloons("leetcode".to_string()), 0);
assert_eq!(Solution::max_number_of_balloons("hpitp".to_string()), 0);
assert_eq!(Solution::max_number_of_balloons("krhizmmgmcrecekgyljqkldocicziihtgpqwbticmvuyznragqoyrukzopfmjhjjxemsxmrsxuqmnkrzhgvtgdgtykhcglurvppvcwhrhrjoislonvvglhdciilduvuiebmffaagxerjeewmtcwmhmtwlxtvlbocczlrppmpjbpnifqtlninyzjtmazxdbzwxthpvrfulvrspycqcghuopjirzoeuqhetnbrcdakilzmklxwudxxhwilasbjjhhfgghogqoofsufysmcqeilaivtmfziumjloewbkjvaahsaaggteppqyuoylgpbdwqubaalfwcqrjeycjbbpifjbpigjdnnswocusuprydgrtxuaojeriigwumlovafxnpibjopjfqzrwemoinmptxddgcszmfprdrichjeqcvikynzigleaajcysusqasqadjemgnyvmzmbcfrttrzonwafrnedglhpudovigwvpimttiketopkvqw".to_string()), 10);
}
}