MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / count_largest_group

Function count_largest_group

1399-count-largest-group.rs:1–15  ·  view source on GitHub ↗
(n: i32)

Source from the content-addressed store, hash-verified

1pub fn count_largest_group(n: i32) -> i32 {
2 let mut count = vec![0;99];
3 for i in 1..=n {
4 let a = i.to_string().chars().map(|c| c.to_digit(10).unwrap()).sum::<u32>();
5 count[a as usize] += 1;
6 }
7 let m = *count.iter().max().unwrap();
8 let mut ret = 0;
9 for i in count {
10 if i == m {
11 ret += 1;
12 }
13 }
14 ret
15}
16
17fn main() {
18 println!("{:?}", count_largest_group(13));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected