Preview:
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
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter