Skip to content

Commit 7b40079

Browse files
committed
Create 1742-maximum-number-of-balls-in-a-box.rs
1 parent e146bd9 commit 7b40079

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
pub fn count_balls(low_limit: i32, high_limit: i32) -> i32 {
2+
use std::collections::HashMap;
3+
let mut mmp = HashMap::new();
4+
for i in low_limit ..= high_limit {
5+
let a = i.to_string().chars().map(|e|e.to_string().parse::<i32>().unwrap()).sum::<i32>();
6+
mmp.entry(a).and_modify(|e|*e += 1).or_insert(1);
7+
}
8+
mmp.into_values().into_iter().max().unwrap()
9+
}
10+
11+
fn main() {
12+
println!("{:?}", count_balls(1, 10));
13+
println!("{:?}", count_balls(5, 15));
14+
println!("{:?}", count_balls(19, 28));
15+
}

0 commit comments

Comments
 (0)