Snippets Collections
def subsetsWithDup(nums):
    res = []
    nums.sort()
    
    
    def dfs(index, path):
        res.append(path)
        for i in range(index, len(nums)):
            if i > index and nums[i] == nums[i-1]:
                continue
            dfs(i+1, path+[nums[i]])
            
    dfs(0, [])
    return res
def subsets1(nums):
    res = []
    nums.sort()
    
    def dfs(index, path):
        res.append(path)
        for i in range(index, len(nums)):
            dfs(i+1, path+[nums[i]])
            
    dfs(0, [])
    return res
star

Thu Mar 10 2022 02:27:47 GMT+0000 (Coordinated Universal Time)

#python #template #subsets
star

Thu Mar 10 2022 02:22:09 GMT+0000 (Coordinated Universal Time) https://leetcode.com/problems/combination-sum/discuss/429538/General-Backtracking-questions-solutions-in-Python-for-reference-%3A

#python #template #subsets

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension