注意点&感悟:
- 复习是个好东西
题目链接:78. 子集
自己独立写的代码:
class Solution:
def subsets(self, nums: List[int]) -> List[List[int]]:
res = []
self.backtracking(nums,0,[],res)
return res
def backtracking(self,nums,start_index,path,res):
# 存结果
res.append(path[:])
# 遍历
for i in range(start_index,len(nums)):
path.append(nums[i])
self.backtracking(nums,i+1,path,res)
path.pop()