Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

README.md

Subsets II

Problem can be found in here!

Solution: Backtracking

def subsetsWithDup(nums: List[int]) -> List[List[int]]:
    def helper(tempt: List[int], index: int):
        result.append(tempt)
        for i in range(index, len(nums)):
            if i > index and nums[i] == nums[i-1]:
                continue
            helper(tempt+[nums[i]], i+1)

    result = []
    nums.sort()
    helper([], 0)
    return result

Time Complexity: O(n*2^n), Space Complexity: O(n), where n is the length of nums.