LeetCode(力扣)216. 组合总和 IIIPython

LeetCode216. 组合总和 III

题目链接

https://leetcode.cn/problems/combination-sum-iii/

代码

python 复制代码
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()
相关推荐
查士丁尼·绵17 分钟前
笔试-士兵过河
python
weixin_466818 分钟前
编程之python基础
开发语言·python
打酱油的;25 分钟前
【无标题】
爬虫·python·php
前端小刘哥29 分钟前
超越“接收端”:解析视频推拉流EasyDSS在RTMP推流生态中的核心价值与中流砥柱作用
算法
前端小刘哥35 分钟前
新版视频直播点播平台EasyDSS用视频破局,获客转化双提升
算法
幸福清风1 小时前
【Python】基于Tkinter库实现文件夹拖拽与选择功能
windows·python·microsoft·tkinter
海琴烟Sunshine1 小时前
leetcode 168. Excel 表列名称 python
python·算法·leetcode
莫叫石榴姐1 小时前
字节数开一面
大数据·数据仓库·职场和发展
java1234_小锋1 小时前
TensorFlow2 Python深度学习 - 卷积神经网络示例2-使用Fashion MNIST识别时装示例
python·深度学习·tensorflow·tensorflow2
京东零售技术1 小时前
探索无限可能:生成式推荐的演进、前沿与挑战
算法