Example with duplicates
Input
nums = [1,1,2]
Output
[[1, 1, 2], [1, 2, 1], [2, 1, 1]]
Although there are 3! = 6 permutations with duplicates considered, only 3 unique permutations exist.
Full lesson preview
Return all unique permutations of a list that may contain duplicates.
Problem statement
Task
Examples
Input
nums = [1,1,2]
Output
[[1, 1, 2], [1, 2, 1], [2, 1, 1]]
Although there are 3! = 6 permutations with duplicates considered, only 3 unique permutations exist.
Input format
Output format
Constraints
Samples
Input
nums = [0,1,0]
Output
[[0, 0, 1], [0, 1, 0], [1, 0, 0]]
Unique permutations of [0,1,0], sorted lexicographically.