python solution 8 lines


  • 0
    G

    '''

    def subsetsWithDup(self, nums):
        res=[[]]
        for val in nums:
            n=len(res)
            for i in range(n):
                #res[i]+[val] would return a new list without affecting the original res[i]
                #sort the list to avoid duplicates
                add=sorted(res[i]+[val])  
                if add not in res:
                    res.append(add)
        return res
    

    '''


Log in to reply
 

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