blob: f380f39a631b5da6abdffb55250f3e052ee5e918 (
plain)
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
|
fn main() {
println!("Hello, world!");
}
struct Solution {}
impl Solution {
pub fn group_the_people(group_sizes: Vec<i32>) -> Vec<Vec<i32>> {
let mut result: Vec<Vec<i32>> = Vec::new();
for (i, size) in group_sizes.iter().enumerate() {
let group = result.iter_mut()
.find(|x| x.capacity() == *size as usize && x.len() != x.capacity());
match group {
Some(entry) => entry.push(i as i32),
None => {
let mut new_group = Vec::with_capacity(*size as usize);
new_group.push(i as i32);
result.push(new_group);
}
};
}
result
}
}
|