标签:
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; } }
标签:
原文地址:http://www.cnblogs.com/liujinhong/p/5631594.html