Question
k
represents the number that can be selected for each combination, n
represents the target sum, the selectable numbers are 1 to 9, each number in each combination can only be selected once. Return all combinations that add up up to n
.
Similar Questions
- Medium - 39. Combination Sum
Solution
A very typical backtracking or DFS problem. Consider all situations, and then determine in turn.
The backtracking method can be regarded as a template. The overall framework is a larger for
loop, then add first, then use recursion to traverse, then remove and continue the loop.
1 | public List<List<Integer>> combinationSum3(int k, int n) { |