# Middle-题目26：216. Combination Sum III

Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.

Ensure that numbers within the set are sorted in ascending order.
Example 1:
Input: k = 3, n = 7
Output:
[[1,2,4]]
Example 2:
Input: k = 3, n = 9
Output:
[[1,2,6], [1,3,5], [2,3,4]]

backtrack(List<List<Integer>> list,List<Integer> sublist,int k,int n,int start)

public class Solution {
public List<List<Integer>> combinationSum3(int k, int n) {
List<List<Integer>> list=new ArrayList<List<Integer>>();
backtrack(list,new ArrayList<Integer>(),k,n,1);
return list;
}
private void backtrack(List<List<Integer>> list,List<Integer> sublist,int k,int n,int start) {
if(k == 1 ) {
if(n < 10) {
List<Integer> sublist2=new ArrayList<Integer>(sublist);
return;
}
}
else {
for(int i=start;i<(double)n/(double)k;i++) {
backtrack(list,sublist,k-1,n-i,i+1);
sublist.remove(sublist.size()-1);
}
}
}
}

1ms，beats 52.84%，众数1ms，47.16%
Cmershen的碎碎念：

#### 【LeetCode-面试算法经典-Java实现】【216-Combination Sum III （组合数的和）】

2015-08-28 06:58:38

#### [LeetCode 216] Combination Sum III

2015-09-16 15:35:39

#### leetcode 216 Combination Sum III java 算法

2016-07-15 16:09:29

#### LeetCode - 216. Combination Sum III - 思路详解 - C++

2017-01-13 21:06:41

#### Leetcode 39 Combination Sum & 40 Combination Sum II & 216 Combination Sum III & 377 Combination V

2016-07-26 13:38:06

#### LeetCode 216. Combination Sum III（数字之和）

2016-05-06 04:17:52

#### leetcode【39+40+216+377 Combination Sum 相关】【python】

2016-12-13 16:38:48

#### 【LEETCODE】216-Combination Sum III [Python]

2016-01-07 10:55:09

#### 216. Combination Sum III

2016-03-12 03:40:40