zoukankan      html  css  js  c++  java
  • LeetCode OJ combine 3

    public class Solution {
        public List<List<Integer>> combinationSum3(int k, int n) {
            return combination(k, n, 1);
        }
        
        public List<List<Integer>> combination(int k, int target, int start) {
            List<List<Integer>> list = new ArrayList<>();
            if(k <= 0) return list;
            
            for(int i = start; i <= 10-k; i++){
                if(i < target){
                    List<List<Integer>> tlist = combination(k, target - i, i+1);
                    if(tlist.size() > 0){
                        for(List<Integer> alist : tlist){
                            alist.add(0, i);
                        }
                        list.addAll(tlist);
                    }
                }
                else if(i == target){
                    List<Integer> tlist = new LinkedList<>();
                    tlist.add(target);
                    list.add(tlist);
                }
                else break;
            }
            return list;
        }
    }
  • 相关阅读:
    day89
    day88
    day87
    day86
    day85
    day84
    day83
    Maven仓库汇总
    [转载]AngularJS入门教程04:双向绑定
    [转载]AngularJS入门教程03:迭代器
  • 原文地址:https://www.cnblogs.com/liujinhong/p/5631594.html
Copyright © 2011-2022 走看看