15
15
[3,2,1]
16
16
]*/
17
17
public class _46 {
18
- static class Accepted_solution {
19
- //this solution has a recursive function that has a return type
18
+ static class AcceptedSolution {
19
+ //this solution has a backtracking function that has a return type
20
20
public static List <List <Integer >> permute (int [] nums ) {
21
21
List <List <Integer >> result = new ArrayList ();
22
22
List <Integer > init = new ArrayList <>();
23
23
result .add (init );
24
- return recursive (result , nums , 0 );
24
+ return backtracking (result , nums , 0 );
25
25
}
26
26
27
- private static List <List <Integer >> recursive (List <List <Integer >> result , int [] nums ,
28
- int pos ) {
29
- if (pos == nums .length )
27
+ private static List <List <Integer >> backtracking (List <List <Integer >> result , int [] nums , int pos ) {
28
+ if (pos == nums .length ) {
30
29
return result ;
30
+ }
31
31
List <List <Integer >> newResult = new ArrayList ();
32
32
for (List <Integer > eachList : result ) {
33
33
for (int i = 0 ; i <= eachList .size (); i ++) {
@@ -37,11 +37,11 @@ private static List<List<Integer>> recursive(List<List<Integer>> result, int[] n
37
37
}
38
38
}
39
39
result = newResult ;
40
- return recursive (result , nums , pos + 1 );
40
+ return backtracking (result , nums , pos + 1 );
41
41
}
42
42
}
43
43
44
- static class Accepted_solution_with_void_type {
44
+ static class AcceptedSolutionWithVoidType {
45
45
public static List <List <Integer >> permute (int [] nums ) {
46
46
List <List <Integer >> result = new ArrayList ();
47
47
List <Integer > init = new ArrayList <>();
@@ -60,7 +60,7 @@ private static void recursive(List<List<Integer>> result, int[] nums, int pos) {
60
60
newResult .add (newList );
61
61
}
62
62
}
63
- /**You'll have to use the two lines, instead of this line: result = newResult; otherwise, it won't work!!! Fuck! */
63
+ /**You'll have to use the two lines, instead of this line: result = newResult; otherwise, it won't work!!!*/
64
64
result .clear ();
65
65
result .addAll (newResult );
66
66
0 commit comments