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