首页 > 其他 > 详细

77. Combinations

时间:2017-09-27 09:22:40      阅读:170      评论:0      收藏:0      [点我收藏+]
class Solution {
    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res=new ArrayList<List<Integer>>();
        combine(n, k, new ArrayList<Integer>(), res);
        return res;
    }
    private void combine(int num, int k, List<Integer> list, List<List<Integer>> res){
        if(k==0)
        {
            res.add(new ArrayList<Integer>(list));
            return;
        }
        if(num==0)
            return;
        combine(num-1,k,list,res);
        list.add(num);
        combine(num-1,k-1,list,res);
        list.remove(list.size()-1);
    }
}

 

77. Combinations

原文:http://www.cnblogs.com/asuran/p/7599822.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!