组合总和3
解题思路:递归回溯
class Solution { public List
> result = new ArrayList
>(); public List
> combinationSum3(int k, int n) { List list = new ArrayList<>(); combinationSum3(1,k,n,list); return result; } public void combinationSum3(int start, int k, int n, List list) { if(k==0) { if(n==0) { List newList = (List)((ArrayList)list).clone(); result.add(newList); } return; } for(int i=start;i<10;++i) { list.add(i); combinationSum3(i+1,k-1,n-i,list); list.remove((Integer)i); } }}