subset with duplicate

Solutions on MaxInterview for subset with duplicate by the best coders in the world

showing results for - "subset with duplicate"
Enrico
07 Jan 2021
1class Solution:
2    def subsetsWithDup(self, nums):
3        if not nums:
4            return []
5        nums.sort()
6        res, cur = [[]], []
7        for i in range(len(nums)):
8            if i > 0 and nums[i] == nums[i-1]:
9                cur = [item + [nums[i]] for item in cur]
10            else:
11                cur = [item + [nums[i]] for item in res]
12            res += cur
13        return res
14