Why the following code throw runtime error but run well on my local env


  • 0
    J

    class Solution:

    def getsubsetsWithDup(self,S):
        if len(S)==0:
            return [[]]
        if len(S)==1:
            return [[],[S[0]]]
        
        subresults=self.getsubsetsWithDup(S[1::])
    
       #get TypeError
        results=[[S[0]]+x for x in subresults]
        
          
        results=results+subresults
        
        if [S[0]] in subresults:
            results=results.remove([S[0]])
        return results
    
    # @param num, a list of integer
    # @return a list of lists of integer
    def subsetsWithDup(self, S):
        S.sort()
        return self.getsubsetsWithDup(S)
    

    It got the following result on OJ but pass on my local env.

    TypeError: 'NoneType' object is not iterable (line:11 results=[[S[0]]+x for x in subresults])

    Input:[1,2,2]


Log in to reply
 

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