Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 619 Bytes

47.md

File metadata and controls

21 lines (19 loc) · 619 Bytes

题目地址

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)