代码随想录——组合(Leetcode77)

题目链接
在这里插入图片描述

回溯

class Solution {

    List<List<Integer>> res = new ArrayList<List<Integer>>();
    List<Integer> list = new ArrayList<Integer>();

    public List<List<Integer>> combine(int n, int k) {
        backtracking(n, k, 1);
        return res;
    }

    public void backtracking(int n, int k, int startIndex){
        if(list.size() == k){
            res.add(new ArrayList<>(list));
            return;
        }
        for(int i = startIndex; i <= n; i++){
            list.add(i);
            backtracking(n, k, i + 1);
            list.removeLast();
        }
    }
}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-12 16:10:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-12 16:10:05       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-12 16:10:05       82 阅读
  4. Python语言-面向对象

    2024-06-12 16:10:05       91 阅读

热门阅读

  1. Qt---pro文件的学习

    2024-06-12 16:10:05       29 阅读
  2. Bently nevada 125760-01 数据管理器输入模块

    2024-06-12 16:10:05       28 阅读
  3. python 启动 exe

    2024-06-12 16:10:05       23 阅读
  4. Adobe Illustrator 基础学习

    2024-06-12 16:10:05       26 阅读
  5. Web前端开发新书:探索技术与艺术的交融之旅

    2024-06-12 16:10:05       32 阅读
  6. 如何使用EMQX搭建一个私有的MQTT服务器

    2024-06-12 16:10:05       36 阅读
  7. go-zero入门学习教程(看了就会)

    2024-06-12 16:10:05       31 阅读
  8. TEST!!!!

    TEST!!!!

    2024-06-12 16:10:05      32 阅读
  9. 力扣每日一题-881

    2024-06-12 16:10:05       28 阅读
  10. 【Python】使用Quart作为web服务器

    2024-06-12 16:10:05       34 阅读