Skip to content

Commit c6976ff

Browse files
authored
feat: add rust solution to lc problem: No.1282 (#1604)
1 parent 862740e commit c6976ff

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,27 @@ impl Solution {
196196
}
197197
```
198198

199+
```rust
200+
impl Solution {
201+
#[allow(dead_code)]
202+
pub fn group_the_people(group_sizes: Vec<i32>) -> Vec<Vec<i32>> {
203+
let n = group_sizes.len();
204+
let mut g = vec![vec![]; n + 1];
205+
let mut ret = vec![];
206+
207+
for i in 0..n {
208+
g[group_sizes[i] as usize].push(i as i32);
209+
if g[group_sizes[i] as usize].len() == group_sizes[i] as usize {
210+
ret.push(g[group_sizes[i] as usize].clone());
211+
g[group_sizes[i] as usize].clear();
212+
}
213+
}
214+
215+
ret
216+
}
217+
}
218+
```
219+
199220
### **...**
200221

201222
```

solution/1200-1299/1282.Group the People Given the Group Size They Belong To/README_EN.md

+21
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ impl Solution {
178178
}
179179
```
180180

181+
```rust
182+
impl Solution {
183+
#[allow(dead_code)]
184+
pub fn group_the_people(group_sizes: Vec<i32>) -> Vec<Vec<i32>> {
185+
let n = group_sizes.len();
186+
let mut g = vec![vec![]; n + 1];
187+
let mut ret = vec![];
188+
189+
for i in 0..n {
190+
g[group_sizes[i] as usize].push(i as i32);
191+
if g[group_sizes[i] as usize].len() == group_sizes[i] as usize {
192+
ret.push(g[group_sizes[i] as usize].clone());
193+
g[group_sizes[i] as usize].clear();
194+
}
195+
}
196+
197+
ret
198+
}
199+
}
200+
```
201+
181202
### **...**
182203

183204
```

0 commit comments

Comments
 (0)