[LeetCode]Combinations
来源:互联网 发布:阿里云数据库怎么用 编辑:程序博客网 时间:2024/05/22 02:22
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 {List<Integer> list = new ArrayList<Integer>();List<List<Integer>> res = new ArrayList<>();public List<List<Integer>> combine(int n, int k) {if (n < k) {return res;}combine(n,k,0,1);return res;}private void combine(int n, int k, int len, int start){ if(len == k){ List<Integer> lin = new ArrayList<>(list); res.add(lin); return; } for(int i=start;i<=n;i++){ list.add(i); combine(n,k,len+1,i+1); list.remove(Integer.valueOf(i)); } }}
0 0
- 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】Combinations
- Cannot make a static reference to the non-static method的解决方法 分类: JAVA 2012-09-13 12:01 8386人阅读 评论(0
- /bin/bash^M: bad interpreter: 没有那个文件或目录
- QQ开放战略背后的机遇与挑战
- hdu4112: Break the Chocolate
- AFNetworking源码解析<三>
- [LeetCode]Combinations
- Algorithm系列之汉诺塔(Hanoi)
- Java堆和栈的区别
- C#事件(event)解析
- 黑马程序员-java基础之继承,多态
- c语言关键字--static
- EasyUI 中datagrid 点击表头进行排序
- smartSVN 分支合并到主干上,iOS 编译时链接错误
- EM算法的证明