class Solution {
List<List<Integer>> res = new ArrayList<>();
List<Integer> path = new ArrayList<>();
public List<List<Integer>> combinationSum3(int k, int n) {
combinationSum3(k, n, 1);
return res;
}
public void combinationSum3(int k, int n, int start) {
if (path.size() == k) {
int count = 0;
for (int i = 0; i < path.size(); i++) {
count += path.get(i);
}
if (count == n) {
res.add(new ArrayList<>(path));
}
return;
}
for (int i = start; i <= 9; i++) {
path.add(i);
combinationSum3(k, n, i + 1);
path.remove(path.size() - 1);
}
}
}