Permutations II
Given an integer array nums that may contain duplicates, return all possible unique permutations of nums.
The returned permutations may be in any order. Each permutation must contain every element from nums exactly once, and duplicate permutations must not be included in the result.
Example 1
Input
nums = [1,1,2]Output
[[1,1,2],[1,2,1],[2,1,1]]The two
1 values are duplicates, so only three distinct orderings are possible.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]]All values are distinct, so there are 3! = 6 unique permutations.
Constraints
- 1 <= nums.length <= 8
- -10 <= nums[i] <= 10