代码随想录day 25 回溯算法
题216
找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。
思考:
按照回溯的模版代码,确定好函数参数和全局变量,参考77题,此题不难写出来。
class Solution {
List<List<Integer>> result = new ArrayList<>();
LinkedList<Integer> path = new LinkedList<>();
int count = 0;
public List<List<Integer>> combinationSum3(int k, int n) {
backTracking(k, n, 1);
return result;
}