https://oj.leetcode.com/problems/combinations/

http://blog.csdn.net/linhuanmars/article/details/21260217


public class Solution {
    public List> combine(int n, int k)
    {
        List> results = new ArrayList<>();
        help(n, k, 0, new ArrayList(), results);
        return results;
    }
    
    private void help(int n, int k, int start, List items, List> results)
    {
        if (items.size() == k)
        {
            results.add(new ArrayList(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);
        }
    }
}