Skip to content

Commit 3c09727

Browse files
authored
Create Solution.rs
1 parent a1e5179 commit 3c09727

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
impl Solution {
2+
pub fn count_largest_group(n: i32) -> i32 {
3+
let mut cnt = vec![0; 40];
4+
let mut ans = 0;
5+
let mut mx = 0;
6+
7+
for i in 1..=n {
8+
let mut s = 0;
9+
let mut x = i;
10+
while x > 0 {
11+
s += x % 10;
12+
x /= 10;
13+
}
14+
cnt[s as usize] += 1;
15+
if mx < cnt[s as usize] {
16+
mx = cnt[s as usize];
17+
ans = 1;
18+
} else if mx == cnt[s as usize] {
19+
ans += 1;
20+
}
21+
}
22+
23+
ans
24+
}
25+
}

0 commit comments

Comments
 (0)