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