【LeetCode】 077. Combinations
来源:互联网 发布:诊疗指南软件下载 编辑:程序博客网 时间:2024/05/24 02:37
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],]
public class Solution { public List<List<Integer>> combine(int n, int k) { List<List<Integer>> res = new ArrayList<List<Integer>>(); helper(res, new ArrayList<Integer>(), 1, n, k); return res; } private void helper(List<List<Integer>> res, List<Integer> subList, int start, int n, int k) { if (k == subList.size()) { res.add(new ArrayList<Integer>(subList)); return; } for (int i = start; i <= n; i++) { subList.add(i); helper(res, subList, i + 1, n, k); subList.remove(subList.size() - 1); } }}
0 0
- 【LeetCode】 077. Combinations
- LeetCode: Combinations
- LeetCode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- [LeetCode] Combinations
- Leetcode: Combinations
- LeetCode Combinations
- [Leetcode] Combinations
- [Leetcode] Combinations
- [leetcode] Combinations
- [LeetCode]Combinations
- [leetcode]Combinations
- LeetCode-Combinations
- [leetcode] Combinations
- LeetCode - Combinations
- 【Leetcode】Combinations
- Leetcode: Combinations
- 【LeetCode】 334. Increasing Triplet Subsequence
- 1.15三道水题题解
- 周有光2017年1月14日去世,享年112岁
- python模拟开发一个网站
- The operation couldn’t be completed. Unable to log in with account ''. An unexpected failure occurre
- 【LeetCode】 077. Combinations
- 实现分享到QQ空间 新浪微博等等
- Ashampoo.Snap.9.v9.0.5-AMPED
- Ashampoo.ZIP.Pro.2.v2.0.0-AMPED
- 感谢CSDN网管员,多数科普博文已经恢复搜索访问
- leetcode 485
- BZOJ3107: [cqoi2013]二进制a+b
- RPL(4):RFC6550翻译(4)---RPL的通信流支持&RPL实例
- 【LeetCode】 215. Kth Largest Element in an Array