-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutations II
More file actions
30 lines (29 loc) · 868 Bytes
/
Permutations II
File metadata and controls
30 lines (29 loc) · 868 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
30
class Solution {
public void check(int[] nums, boolean bol[], List<Integer> ds, List<List<Integer>> ans) {
if(ds.size()==nums.length)
{
List<Integer> l=new ArrayList<>(ds);
if(!ans.contains(l))
ans.add(l);
return;
}
for(int i=0;i<nums.length;i++)
{
if(!bol[i])
{
bol[i]=true;
ds.add(nums[i]);
check(nums, bol, ds, ans);
ds.remove(ds.size()-1);
bol[i]=false;
}
}
}
public List<List<Integer>> permuteUnique(int[] nums) {
List<List<Integer>> ans = new ArrayList<>();
List<Integer> ds = new ArrayList<>();
boolean bol[] = new boolean[nums.length];
check(nums, bol, ds, ans);
return ans;
}
}