Python just add one line to subset I solution


  • 0
    H
    class Solution(object):
        def subsetsWithDup(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            res, subset = [],[]
            nums = sorted(nums)
            self.helper(res, subset, nums, 0)
            return res
        
        def helper(self, res, subset, nums, startIndex):
            res.append(list(subset))
            for i in range(startIndex, len(nums)):
                # we choose the number that first appear
                if i != startIndex and i > 0 and nums[i] == nums[i - 1]:
                    continue
                subset.append(nums[i])
                self.helper(res, subset, nums, i + 1)
                subset.pop()
            return
        
        ```

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.