-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0046. Permutations
More file actions
43 lines (36 loc) · 1.15 KB
/
0046. Permutations
File metadata and controls
43 lines (36 loc) · 1.15 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Solution {
List<List<Integer>> lix = new ArrayList<List<Integer>>();
/*public void auxper1(int[] nums,List<Integer> tmp){
if(tmp.size()==nums.length){
lix.add(new ArrayList<Integer>(tmp));
return;
}
for(int i=0;i<nums.length;i++){
if(!tmp.contains(nums[i])){
tmp.add(nums[i]);
auxper(nums,tmp);
tmp.remove(tmp.size()-1);
}
}
}
public List<List<Integer>> permute1(int[] nums) {
auxper(nums, new ArrayList<Integer>());
return lix;
}*/
public void auxper1(List<Integer> tmp, int ix){
if(ix==tmp.size())
lix.add(new ArrayList<Integer>(tmp));
for(int i = ix;i<tmp.size();i++){
Collections.swap(tmp,ix,i);
auxper1(tmp,i+1);
Collections.swap(tmp,ix,i);
}
}
public List<List<Integer>> permute(int[] nums) {
List<Integer> nums_lst = new ArrayList<Integer>();
for (int num : nums)
nums_lst.add(num);
auxper1(nums_lst, 0);
return lix;
}
}