输出一个有重复数字的数组的全排列。
思路: dfs
1234567891011121314151617181920
class Solution: def permuteUnique(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ # 6 star, 排序,然后dfs,需要去重 nums.sort() rs = [] self.dfs(nums, [], rs) return rs def dfs(self, nums, path, rs): if nums == []: rs.append(path) return for i in range(len(nums)): if i > 0 and nums[i] == nums[i-1]: continue self.dfs(nums[:i]+nums[i+1:], path+[nums[i]], rs)