###### [Lintcode]Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.

Example

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 {
/**
* @param n: Given the range of numbers
* @param k: Given the numbers of combinations
* @return: All the combinations of k numbers out of 1..n
*/
public List<List<Integer>> combine(int n, int k) {
if(k > n) return null;
List<List<Integer>> res = new ArrayList<List<Integer>>();
helper(res, new ArrayList<Integer>(), n, k, 1);
return res;
}

void helper(List<List<Integer>> res, List<Integer> list, int n, int k, int index) {
if(k == 0){
return;
}
for(int i = index; i <= n; i++) {
helper(res, list, n, k - 1, i + 1);
list.remove(list.size() - 1);
}
}
}

#### LeetCode 77 Combinations (Python详解及实现)

2017-08-08 13:50:46

#### LintCode 135. Combination Sum

2018-02-16 11:39:54

#### leetCode 22.Generate Parentheses (生成括号) 解题思路和方法

2015-07-06 22:11:08

#### lintcode: Combinations

2016-03-29 17:43:36

#### Python使用combinations实现排列组合

2017-07-30 17:25:14

#### 排列组合 permutations and combinations

2013-01-21 18:27:47

#### <LeetCode OJ> 77. Combinations

2016-03-09 15:35:14

#### leetcode 77. Combinations-排列|递归|非递归|Java|Python

2016-06-02 10:43:01

#### 77 Combinations

2015-10-25 16:20:02

#### LeetCode 17 Letter Combinations of a Phone Number(C,C++,Java,Python)

2015-05-10 13:39:32

## 不良信息举报

[Lintcode]Combinations