Skip to content

Files

Latest commit

bf89471 · Oct 5, 2022

History

History

90-SubsetsII

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 5, 2022
Oct 5, 2022

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.