# Permutations II

Given a collection of numbers, `nums`, that might contain duplicates, return all possible unique permutations in any order.

Example 1:

```Input: nums = [1,1,2]
Output:
[[1,1,2],
[1,2,1],
[2,1,1]]
```

Example 2:

```Input: nums = [1,2,3]
Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
```

Constraints:

• `1 <= nums.length <= 8`
• `-10 <= nums[i] <= 10`
```class Solution {
public List<List<Integer>> permuteUnique(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
if (nums == null || nums.length == 0) {
return result;
}
Arrays.sort(nums);
List<Integer> current = new ArrayList<>();
boolean[] used = new boolean[nums.length];
permuteUnique(nums, current, used, result);
return result;
}

private void permuteUnique(int[] nums, List<Integer> current,
boolean[] used, List<List<Integer>> result) {
if (current.size() == nums.length) {
} else {
for (int i = 0; i < nums.length; i++) {
int cur = nums[i];
if (used[i]) continue;
if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1]) {
continue;
}