- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpermutations.java
More file actions
Latest commit
29 lines (27 loc) · 907 Bytes
/
Copy pathpermutations.java
File metadata and controls
29 lines (27 loc) · 907 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
29
publicclassSolution {
voidpermuteArray(int [] num, intbegin,ArrayList<ArrayList<Integer>> result) {
if(begin==num.length-1) {
ArrayList<Integer> tempResult = newArrayList<Integer>();
for(inti=0;i<num.length;i++) {
tempResult.add(num[i]);
}
result.add(tempResult);
return;
}
inttemp;
for(inti=begin;i<num.length;i++) {
temp = num[begin];
num[begin] = num[i];
num[i] = temp;
permuteArray(num, begin+1,result);
temp = num[begin];
num[begin] = num[i];
num[i] = temp;
}
}
publicArrayList<ArrayList<Integer>> permute(int[] num) {
ArrayList<ArrayList<Integer>> result = newArrayList<ArrayList<Integer>>();
permuteArray(num,0,result);
returnresult;
}
}