Why I got an error using python?


  • 0
    L
    class Solution(object):
        res = []
        solution = []
        def subsetsWithDup(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            l = len(nums)
            nums.sort()
            for i in range(l+1):
                self.helper(nums, i, 0)
            return self.res
        
        def helper(self, nums, number, cp):
            if len(self.solution) == number:
                temp = self.solution[:]
                if temp not in self.res:
                    self.res.append(temp)
                return
            for i in range(cp, len(nums)):
                self.solution.append(nums[i])
                self.helper(nums,number,i+1)
                self.solution.pop()
    

    when the input is [1,1], the given output is [[],[0],[1],[1,1]]. Where is the [0] comes from?


Log in to reply
 

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