diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md index 3d17d1eee2adf..6af55770c9651 100644 --- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md +++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md @@ -196,6 +196,27 @@ impl Solution { } ``` +```rust +impl Solution { + #[allow(dead_code)] + pub fn group_the_people(group_sizes: Vec) -> Vec> { + let n = group_sizes.len(); + let mut g = vec![vec![]; n + 1]; + let mut ret = vec![]; + + for i in 0..n { + g[group_sizes[i] as usize].push(i as i32); + if g[group_sizes[i] as usize].len() == group_sizes[i] as usize { + ret.push(g[group_sizes[i] as usize].clone()); + g[group_sizes[i] as usize].clear(); + } + } + + ret + } +} +``` + ### **...** ``` diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md index faac6b1b0e4fc..e91a93fb30c95 100644 --- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md +++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md @@ -178,6 +178,27 @@ impl Solution { } ``` +```rust +impl Solution { + #[allow(dead_code)] + pub fn group_the_people(group_sizes: Vec) -> Vec> { + let n = group_sizes.len(); + let mut g = vec![vec![]; n + 1]; + let mut ret = vec![]; + + for i in 0..n { + g[group_sizes[i] as usize].push(i as i32); + if g[group_sizes[i] as usize].len() == group_sizes[i] as usize { + ret.push(g[group_sizes[i] as usize].clone()); + g[group_sizes[i] as usize].clear(); + } + } + + ret + } +} +``` + ### **...** ```