Python Simple Solution: Beat 90%


  • 0
    D
    from collections import Counter
    class Solution(object):
        def subsetsWithDup(self, nums):
            """
            :type nums: List[int]
            :rtype: List[List[int]]
            """
            if nums ==[]: return []
            count = Counter(nums)
            r = []
            nums = count.keys()
            n = len(nums)
            for i in range(n):
                c = count[nums[i]]
                new_list = [[nums[i]]*x for x in range(1, c+1)]
                copy = r[:]
                for l in copy:
                    for n in new_list:
                        r += [l + n]
                r += new_list
            return r + [[]]
    

Log in to reply
 

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