File size: 613 Bytes
75cb225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
impl Solution {
    pub fn valid_k_values(n: usize, cnt: Vec<i32>) -> Vec<i32> {
        let mut ans: Vec<i32> = Vec::new();
        let mut k: usize = 1;

        while k <= n {
            let k_i32: i32 = k as i32;
            let mut b: usize = 0;
            let mut bad_idx: i32 = -1;

            while b < 30 {
                if bad_idx == -1 && cnt[b] % k_i32 != 0 {
                    bad_idx = b as i32;
                }
                b = b + 1;
            }

            if bad_idx == -1 {
                ans.push(k as i32);
            }

            k = k + 1;
        }

        ans
    }
}