class Solution {
public List<List<Integer>> combinationSum3(int k, int n) {
List<List<Integer>> resultList = new ArrayList<>();
List<Integer> result = new ArrayList<>();
int start = 1;
helper(k, n, result, resultList, start);
return resultList;
}
private void helper(int k,
int target,
List<Integer> result,
List<List<Integer>> resultList,
int start) {
if(k < 0) return;
if(k == 0 && target == 0) {
resultList.add(new ArrayList<>(result));
return;
}
for(int i = start; i < 10; i++) {
result.add(i);
helper(k - 1, target - i, result, resultList, i + 1);
result.remove(result.size() - 1);
}
}
}
Combination Sum III leetcode java 走地牙
最新推荐文章于 2022-11-19 15:13:23 发布
