47. Permutations II

47. Permutations II

class Solution:
    def permuteUnique(self, nums: List[int]) -> List[List[int]]:
        self.res=[]
        nums.sort()
        self.dfs(nums,[])
        return self.res

    def dfs(self,nums,path):
        if not nums:
            self.res.append(path)
        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]])

计数问题

你可能感兴趣的:(leetcode)