https://leetcode-cn.com/problems/permutations-ii/
class Solution:
def permuteUnique(self, nums: List[int]) -> List[List[int]]:
""" 全排列II, 给定一个可包含重复数字的序列,返回所有不重复的全排列。"""
res = []
self.dfs(nums, [], res)
return res
def dfs(self, nums, path, res):
if not nums:
res.append(path)
for i in range(len(nums)):
if nums[i] in nums[:i]:
continue
else:
self.dfs(nums[:i] + nums[i + 1:], path + [nums[i]], res)