- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem46.java
More file actions
Latest commit
28 lines (25 loc) · 701 Bytes
/
Copy pathProblem46.java
File metadata and controls
28 lines (25 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
importjava.util.*;
classProblem46 {
publicstaticvoidmain(String[] args) {
int[] nums = newint[]{1, 2, 3, 4};
System.out.println(newProblem46().permute(nums));
}
publicList<List<Integer>> permute(int[] nums) {
List<List<Integer>> list = newArrayList<>();
permute(list, nums, 0);
returnlist;
}
publicvoidpermute(List<List<Integer>> list, int[] nums, intstart) {
List<Integer> res = newArrayList<>();
if(start == nums.length-1) {
return;
} else {
permute(list, nums, start++);
if (list.size() > 0) {
for (inti =0; i < list.size(); i++) {
list.get(i).add(nums[start]);
}
}
}
}
}