parent
8f8c59aeed
commit
d59bc2ee16
|
|
@ -359,6 +359,36 @@ function permute(nums: number[]): number[][] {
|
|||
};
|
||||
```
|
||||
|
||||
### Rust
|
||||
|
||||
```Rust
|
||||
impl Solution {
|
||||
fn backtracking(result: &mut Vec<Vec<i32>>, path: &mut Vec<i32>, nums: &Vec<i32>, used: &mut Vec<bool>) {
|
||||
let len = nums.len();
|
||||
if path.len() == len {
|
||||
result.push(path.clone());
|
||||
return;
|
||||
}
|
||||
for i in 0..len {
|
||||
if used[i] == true { continue; }
|
||||
used[i] = true;
|
||||
path.push(nums[i]);
|
||||
Self::backtracking(result, path, nums, used);
|
||||
path.pop();
|
||||
used[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn permute(nums: Vec<i32>) -> Vec<Vec<i32>> {
|
||||
let mut result: Vec<Vec<i32>> = Vec::new();
|
||||
let mut path: Vec<i32> = Vec::new();
|
||||
let mut used = vec![false; nums.len()];
|
||||
Self::backtracking(&mut result, &mut path, &nums, &mut used);
|
||||
result
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### C
|
||||
|
||||
```c
|
||||
|
|
|
|||
Loading…
Reference in New Issue