subsets
[
[3],
[1],
[2],
[1,2,3],
[1,3],
[2,3],
[1,2],
[]
]
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
res =[]
n = len(nums)
def dfs(pos, path):
res.append(path)
for i in range(pos,n):
dfs(i+1,path+[nums[i]])#注意是i+1
dfs(0,[])
return res
Last updated