https://oj.leetcode.com/problems/combinations/
http://blog.csdn.net/linhuanmars/article/details/21260217
public class Solution {
public List<List<Integer>> combine(int n, int k)
{
List<List<Integer>> results = new ArrayList<>();
help(n, k, 0, new ArrayList<Integer>(), results);
return results;
}
private void help(int n, int k, int start, List<Integer> items, List<List<Integer>> results)
{
if (items.size() == k)
{
results.add(new ArrayList<Integer>(items));
return;
}
for (int i = start ; i < n ; i ++)
{
// Not using used
// is because we don‘t care about order.
// Only go forwards.
//
// If order matters, need to use used:boolean[]
items.add(i + 1);
help(n, k, i + 1, items, results);
items.remove(items.size() - 1);
}
}
}原文地址:http://7371901.blog.51cto.com/7361901/1598998