MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / permute_add

Method permute_add

46. Permutations/src/main.rs:17–30  ·  view source on GitHub ↗
(permutation: &mut Vec<Vec<i32>>, elem: i32)

Source from the content-addressed store, hash-verified

15 }
16
17 pub fn permute_add(permutation: &mut Vec<Vec<i32>>, elem: i32) {
18 if permutation.len() == 0 {
19 permutation.push(vec![elem]);
20 return
21 }
22 for _ in 0..permutation.len() {
23 let base = permutation.remove(0);
24 for i in 0..base.len() + 1 {
25 let mut new_elem = base.clone();
26 new_elem.insert(i, elem);
27 permutation.push(new_elem);
28 }
29 }
30 }
31}
32
33#[cfg(test)]

Callers

nothing calls this directly

Calls 3

removeMethod · 0.80
pushMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected