当前位置: 首页 > article >正文

力扣 中等 216组合总和III

文章目录

  • 题目介绍
  • 解法

题目介绍

在这里插入图片描述

解法

是77.组合链接的扩展

class Solution {
    List<List<Integer>> result= new ArrayList<>();
    List<Integer> path = new ArrayList<>();
    public List<List<Integer>> combinationSum3(int n, int k) {
        dfs(n, k, 1, 0);
        return result;
    }
    public void dfs(int targetSum, int k, int startIndex, int sum){
        if (path.size() == k){
            if (sum == targetSum){
                result.add(new ArrayList<>(path));
            }
            return;
        }
        for (int i = startIndex;i <= 9;i++){
            path.add(i);
            sum += i;
            dfs(targetSum, k, i + 1, sum);
            path.remove(path.size() - 1);
            sum -= i;
        }
    }
}

http://www.kler.cn/news/337635.html

相关文章:

  • tcpdump-arm平台移植
  • 油卡回收源码含教程
  • Linux 系统成为隐秘“Perfctl”加密挖矿恶意软件的目标
  • 第五弹:C++ 面向对象编程中的多态及相关概念详解
  • 计算机网络:物理层 —— 信道及其极限容量
  • 代码随想录算法训练营day50
  • webpack信息泄露
  • 软考高级之系统架构师之计算机硬件基础
  • Leetcode: 0001-0010题速览
  • 【rCore OS 开源操作系统】Rust HashMap应用 知识点及练习题
  • ES(Elasticsearch)SSL集群部署
  • slurm上使用jupyter
  • uniapp生成随机数
  • 2-112基于matlab的协同干扰功率分配模型
  • FWA(固定无线接入),CPE(客户终端设备)简介
  • VADv2 论文学习
  • 【12月IEEE出版* 镇江 】第九届清洁能源与发电技术国际学术会议(CEPGT 2024)
  • EDA脚本应用领域及使用特点
  • 【重学 MySQL】四十三、多行子查询
  • 踩坑spring cloud gateway /actuator/gateway/refresh不生效