回顾复习-回溯算法-78. 子集

注意点&感悟:

  • 复习是个好东西

题目链接: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()

通过截图:

posted @ 2024-02-19 09:00  o蹲蹲o  阅读(2)  评论(0编辑  收藏  举报