0
点赞
收藏
分享

微信扫一扫

使用Vagrant创建和管理本地Kubernetes(K8s)集群的步骤是什么

Brose 2023-09-09 阅读 40

LeetCode216. 组合总和 III

题目链接

https://leetcode.cn/problems/combination-sum-iii/
在这里插入图片描述

代码

class Solution:
    def combinationSum3(self, k: int, n: int) -> List[List[int]]:
        result=[]
        self.backtracking(n, k, 0, 1, [], result)
        return result

    def backtracking(self, targetsum, k, currentsum, startindex, path, result):
        if currentsum > targetsum:
            return 
        
        if len(path) == k:
            if currentsum == targetsum:
                result.append(path[:])
            return
        for i in range(startindex, 9 - (k - len(path)) + 2):
            currentsum += i
            path.append(i)
            self.backtracking(targetsum, k, currentsum, i + 1, path, result)
            currentsum -= i
            path.pop()
举报

相关推荐

0 条评论