78. Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
- 运用迭代的方法
- 通过观察发现每多一位,那么将这位添加到所有之前已经生成的子集中,在添加其中形成新的子集
def subsets(self, nums: List[int]) -> List[List[int]]:
res = [[]]
for i in nums:
res = res + [[i] + num for num in res]
return res