1
class Solution {
2
public List<List<Integer>> permuteUnique(int[] nums) {
3
List<List<Integer>> ans = new ArrayList<>();
4
Arrays.sort(nums);
5
boolean used[] = new boolean[nums.length];
6

7
permutationsFinder(nums, ans, new ArrayList<>(), used);
8

9
return ans;
10
}
11

12
static void permutationsFinder(
13
int[] nums, List<List<Integer>> ans, List<Integer> list, boolean used[]) {
14
if (list.size() == nums.length) {
15
ans.add(new ArrayList<>(list));
16
return;
17
}
18

19
for (int i = 0; i < nums.length; i++) {
20
if (used[i]) continue;
21
if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1]) continue;
22
list.add(nums[i]);
23
used[i] = true;
24
permutationsFinder(nums, ans, list, used);
25
list.remove(list.size() - 1);
26
used[i] = false;
27
}
28
}
29
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0