Maximum Number of Groups Entering a Competition LeetCode solution in Rust

1
/// @author: Leon
2
/// https://leetcode.com/problems/maximum-number-of-groups-entering-a-competition/
3
/// Time Complexity: O(`len_gs`)
4
/// Space Complexity: O(1)
5
impl Solution {
6
pub fn maximum_groups(grades: Vec<i32>) -> i32 {
7
let len_gs: i32 = grades.len() as i32;
8
let mut cnt: i32 = 0;
9
// the running length of the (current) subarray
10
let mut len: i32 = 1;
11
// the accumulated sum of lengths (of subarrays)
12
let mut sum: i32 = 0;
13
while sum + len <= len_gs {
14
cnt += 1;
15
sum += len;
16
len += 1;
17
}
18
cnt
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0