77. Combinations
来源:互联网 发布:送礼物的淘宝店铺 编辑:程序博客网 时间:2024/05/20 00:35
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.
For example,
If n = 4 and k = 2, a solution is:
[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]程序如下所示:
class Solution { public void backTracing(List<List<Integer>> llst, List<Integer> lst, int begin, int n, int k){ if (k == 0){ llst.add(new ArrayList<Integer>(lst)); return; } for (int i = begin; i <= n; ++ i){ lst.add(i); backTracing(llst, lst, i + 1, n, k - 1); lst.remove(lst.size() - 1); } } public List<List<Integer>> combine(int n, int k) { List<Integer> lst = new ArrayList<>(); List<List<Integer>> llst = new ArrayList<>(); backTracing(llst, lst, 1, n, k); return llst; }}
阅读全文
0 0
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 77. Combinations
- 固态硬盘win10升级之后出现硬盘掉速现象?已解决
- Python hashlib 使用
- extern 用法,全局变量与头文件(重复定义)
- UNIX环境高级编程学习环境搭建---apue.h(第三版)
- 硬链接与软连接
- 77. Combinations
- 链表的创建,遍历以及删除
- redis之set(6)
- Python实现快速排列算法
- Cocos2d 学习,记忆数字游戏
- 第一部分:基础问题 1.6
- 人工智能之机器学习路线图
- Android学习之解决7.0以上版本闪退的一个问题
- 【数据库基础】关系数据库规范化理论之范式