Android大法好！！

###### leetCode 39.Combination Sum(组合总和) 解题思路和方法
Combination Sum

Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.

The same repeated number may be chosen from C unlimited number of times.

Note:
All numbers (including target) will be positive integers.
Elements in a combination (a1, a2, … , ak) must be in non-descending order. (ie, a1 ≤ a2 ≤ … ≤ ak).
The solution set must not contain duplicate combinations.
For example, given candidate set 2,3,6,7 and target 7,
A solution set is:
[7]

[2, 2, 3]

public class Solution {
public List<List<Integer>> combinationSum(int[] a, int t) {
List<List<Integer>> list = new ArrayList<List<Integer>>();
Arrays.sort(a);//数组排序
//各种特殊情况
if(a.length == 0 || a[0] > t)
return list;

int len = 0;
for(int i = 0; i< a.length;i++){
if(a[i] == t){
List<Integer> al = new ArrayList<Integer>();
}
}else if(a[i] < t){//只要比target小的值，大的值肯定不满足，排除
a[len++] = a[i];//新数组
}
}
//只存在a[0] < target 或 a[0] > target
if(a[0] > t)//肯定已没有符合要求的组合
return list;
//a[0] < target

for(int i = 0; i < len; i++){//循环搜索符合要求的数字组合
int[] b = Arrays.copyOfRange(a, i, len);//不含>=t数据的新数组
if(a[i] > t)//如果a[i]，肯定以后的数据已不符合，返回
break;
//相等于已经有了一个值a[0]了
List<List<Integer>> newList = new ArrayList<List<Integer>>();
newList = combinationSum(b,t-a[i]);
if(newList.size() > 0){//里面有符合要求的数据
for(int j = 0; j < newList.size();j++){
Collections.sort(newList.get(j));//排序
}
}
}
return list;
}
}

#### LeetCode39:Combination Sum

2015-07-06 20:58:02

#### Leetcode #39. Combination Sum 组合求和 解题报告

2016-04-10 23:42:47

#### 回溯详解及其应用：Leetcode 39 combination sum

2017-01-31 16:47:37

#### [leetcode]39. Combination Sum,python实现【Medium难度】

2016-06-16 17:01:20

#### [LeetCode 39&40] Combination Sum I & II

2015-03-28 23:41:07

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

2016-12-13 16:38:48

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

2016-07-26 13:38:06

#### leetcode 39. Combination Sum-回溯算法|递归|非递归

2016-03-15 17:37:26

#### LeetCode 39. Combination Sum（组合求和）

2016-05-20 10:40:51

#### <LeetCode>39. 组合总和

2018-04-19 17:22:32

## 不良信息举报

leetCode 39.Combination Sum(组合总和) 解题思路和方法