题目
Given a set of distinct integers, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
解题思路
从空开始,每一步都向子集添加新的整数,并生成新的子集
代码
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
res = [[]]
for num in nums:
res += [item+[num] for item in res]
return res