We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9da072d commit 5968b8fCopy full SHA for 5968b8f
rust/0046-permutations.rs
@@ -0,0 +1,21 @@
1
+impl Solution {
2
+ fn backtrack(first: usize, result: &mut Vec<Vec<i32>>, nums: &mut Vec<i32>) {
3
+ if first == nums.len() {
4
+ result.push(nums.to_owned());
5
+ return;
6
+ }
7
+
8
+ for i in first..nums.len() {
9
+ nums.swap(first, i);
10
+ Solution::backtrack(first + 1, result, nums);
11
12
13
14
15
+ pub fn permute(nums: Vec<i32>) -> Vec<Vec<i32>> {
16
+ let (mut result, mut nums) = (vec![], nums);
17
+ Self::backtrack(0, &mut result, &mut nums);
18
19
+ result
20
21
+}
0 commit comments