描述
Given a collection of numbers that might contain duplicates, return all possible unique permutations.
For example,
[1,1,2] have the following unique permutations:
[1,1,2], [1,2,1], and [2,1,1].
分析
这次数组中有重复值,用next permutation
法的话,上一题Permutations的答案可以直接用。DFS的话要判断当前元素被用了几次。
代码
Next Permutation
DFS
1 | class Solution(object): |