class Solution {
List<List<Integer>> result = new ArrayList<>();
LinkedList<Integer> path = new LinkedList<>();
public List<List<Integer>> combinationSum3(int k, int n) {
backtracking(k,n,1,0);
return result;
}
public void backtracking(int k,int target, int startIndex, int sum){
if(sum > target){
return;
}
if(path.size()== k){
if(sum == target) result.add(new ArrayList<>(path));
return;
}
for(int i = startIndex; i<= 9-(k-path.size())+1;i++){
path.add(i);
sum += i;
backtracking(k,target,i+1,sum);
path.removeLast();
sum -= i;
}
}
}