Description
Given a list of numbers with duplicate number in it. Find all unique permutations.
Example
Example 1:
Input: [1,1]
Output:
[
[1,1]
]
Example 2:
Input: [1,2,2]
Output:
[
[1,2,2],
[2,1,2],
[2,2,1]
]
Challenge
Using recursion to do it is acceptable. If you can do it without recursion, that would be great!
思路:
与没有重复的全排列类似,只是多了一步去重,所以要先对数组排序,然后如果一个数与它前面的数相等而它前面的数又不在排列中那么它也不应该出现在排列中。
代码:
网友评论