subsets_ii
1# @leet start 2class Solution: 3 def subsetsWithDup(self, nums: list[int]) -> list[list[int]]: 4 """ 5 This question asks us to find the subsets if there are duplicates. 6 To do this, I just found all the subsets, and then collected the 7 non-duplicate results in a set and then returned that list. 8 """ 9 res = [[]] 10 11 for num in nums: 12 res.extend([curr + [num] for curr in res]) 13 14 res = set(map(lambda x: tuple(sorted(x)), res)) 15 16 return list(res) 17 18 19# @leet end 20 21 22def test(): 23 assert 2 + 2 == 4
class
Solution:
3class Solution: 4 def subsetsWithDup(self, nums: list[int]) -> list[list[int]]: 5 """ 6 This question asks us to find the subsets if there are duplicates. 7 To do this, I just found all the subsets, and then collected the 8 non-duplicate results in a set and then returned that list. 9 """ 10 res = [[]] 11 12 for num in nums: 13 res.extend([curr + [num] for curr in res]) 14 15 res = set(map(lambda x: tuple(sorted(x)), res)) 16 17 return list(res)
def
subsetsWithDup(self, nums: list[int]) -> list[list[int]]:
4 def subsetsWithDup(self, nums: list[int]) -> list[list[int]]: 5 """ 6 This question asks us to find the subsets if there are duplicates. 7 To do this, I just found all the subsets, and then collected the 8 non-duplicate results in a set and then returned that list. 9 """ 10 res = [[]] 11 12 for num in nums: 13 res.extend([curr + [num] for curr in res]) 14 15 res = set(map(lambda x: tuple(sorted(x)), res)) 16 17 return list(res)
This question asks us to find the subsets if there are duplicates. To do this, I just found all the subsets, and then collected the non-duplicate results in a set and then returned that list.
def
test():