Skip to content

Commit 12d910f

Browse files
authored
Update README.md
1 parent 3c09727 commit 12d910f

File tree

1 file changed

+30
-0
lines changed
  • solution/1300-1399/1399.Count Largest Group

1 file changed

+30
-0
lines changed

solution/1300-1399/1399.Count Largest Group/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,36 @@ function countLargestGroup(n: number): number {
197197
}
198198
```
199199

200+
#### Rust
201+
202+
```rust
203+
impl Solution {
204+
pub fn count_largest_group(n: i32) -> i32 {
205+
let mut cnt = vec![0; 40];
206+
let mut ans = 0;
207+
let mut mx = 0;
208+
209+
for i in 1..=n {
210+
let mut s = 0;
211+
let mut x = i;
212+
while x > 0 {
213+
s += x % 10;
214+
x /= 10;
215+
}
216+
cnt[s as usize] += 1;
217+
if mx < cnt[s as usize] {
218+
mx = cnt[s as usize];
219+
ans = 1;
220+
} else if mx == cnt[s as usize] {
221+
ans += 1;
222+
}
223+
}
224+
225+
ans
226+
}
227+
}
228+
```
229+
200230
<!-- tabs:end -->
201231

202232
<!-- solution:end -->

0 commit comments

Comments
 (0)