@@ -27,24 +27,23 @@ public static class Solution1 {
27
27
public List <List <Integer >> permute (int [] nums ) {
28
28
List <List <Integer >> result = new ArrayList ();
29
29
result .add (new ArrayList <>());
30
- return backtracking (result , nums , 0 );
30
+ return backtracking (nums , 0 , result );
31
31
}
32
32
33
- private List <List <Integer >> backtracking (List < List < Integer >> result , int [] nums , int pos ) {
34
- if (pos == nums .length ) {
33
+ private List <List <Integer >> backtracking (int [] nums , int index , List < List < Integer >> result ) {
34
+ if (index == nums .length ) {
35
35
return result ;
36
36
}
37
- List <List <Integer >> newResult = new ArrayList ();
37
+ List <List <Integer >> newResult = new ArrayList <> ();
38
38
for (List <Integer > eachList : result ) {
39
39
for (int i = 0 ; i <= eachList .size (); i ++) {
40
- //attn: i starts from 0
41
- List <Integer > newList = new ArrayList (eachList );
42
- newList .add (i , nums [pos ]);
40
+ List <Integer > newList = new ArrayList <>(eachList );
41
+ newList .add (i , nums [index ]);
43
42
newResult .add (newList );
44
43
}
45
44
}
46
45
result = newResult ;
47
- return backtracking (result , nums , pos + 1 );
46
+ return backtracking (nums , index + 1 , result );
48
47
}
49
48
}
50
49
0 commit comments