We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a1e5179 commit 3c09727Copy full SHA for 3c09727
solution/1300-1399/1399.Count Largest Group/Solution.rs
@@ -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