[leetCode刷题笔记]77. Combinations
来源:互联网 发布:石油进口数据 编辑:程序博客网 时间:2024/06/06 20:27
使用backtrack的方法。对过程进行递归。
public class Solution { public List<List<Integer>> combine(int n, int k) { List<List<Integer>> combs = new ArrayList<List<Integer>>(); combine(combs, new ArrayList<Integer>(), 1, n, k); return combs; } private void combine(List<List<Integer>> combs, List<Integer> comb, int start, int n, int k) { if (k == 0) { combs.add(new ArrayList<Integer>(comb)); return; } for (int i = start; i <= n; i++) { comb.add(i); combine(combs, comb, i + 1, n, k - 1); // before enter next step, delete old step comb.remove(comb.size() - 1); } }}
0 0
- [leetCode刷题笔记]77. Combinations
- 【leetCode刷题日记】 77. Combinations
- [leetcode刷题系列]Combinations
- LeetCode刷题笔录Combinations
- leetcode学习笔记:Combinations & Subsets
- LeetCode 77. Combinations
- [LeetCode]77.Combinations
- LeetCode --- 77. Combinations
- [Leetcode] 77. Combinations
- [leetcode] 77.Combinations
- leetCode 77.Combinations (组合)
- [leetcode] 77. Combinations
- 77. Combinations LeetCode
- <LeetCode OJ> 77. Combinations
- [LeetCode]77. Combinations
- leetcode 77. Combinations
- LeetCode *** 77. Combinations
- leetcode 77. Combinations
- shell spawn
- centos安装jdk、tomcat、mysql环境
- 设计模式之享元模式
- spring-boot整合mybatis
- My First RPG Game总结三
- [leetCode刷题笔记]77. Combinations
- Hill 加密算法
- 11步教你入门webservice
- Matlab研究小问题:如何计算一条线段所经过的网格区域和各区域内的长度
- redis常用的几种数据类型介绍
- python num
- redis常用命令(基础篇)
- 001-开始golang开发之旅
- redis常用命令(高级篇)