给定一个可包含重复数字的序列,返回所有不重复的全排列。
示例:
输入: [1,1,2] 输出: [ [1,1,2], [1,2,1], [2,1,1] ]
class Solution:
def permuteUnique(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
if len(nums) <= 1:return [nums]
res = []
for i in range(len(nums)):
for j in self.permuteUnique(nums[:i]+nums[i+1:]):
res.append([nums[i]]+j)
cr = []
for i in res:
if i not in cr:cr.append(i)
res = cr
return res