Python 69ms solution using itertools.combination


  • 0
    A
    from itertools import combinations as c
    class Solution(object):
        def subsetsWithDup(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            sol=[]
            nums.sort()
            for i in range(len(nums)+1):
                sol.append(list(set(c(nums,i))))
            
            return [item for sublist in sol for item in sublist ]    
    

Log in to reply
 

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