[刷题]Combination Sum

[LintCode]Combination Sum

public class Solution {
/**
* @param candidates: A list of integers
* @param target:An integer
* @return: A list of lists of integers
*/
public List<List<Integer>> combinationSum(int[] candidates, int target) {
// 2015-08-28
// candicates中不含重复元素，元素可以重复使用
// 解集中不可以含相同解
List<List<Integer>> rst = new ArrayList<List<Integer>>();
if (candidates == null || candidates.length == 0) {
return rst;
}

List<Integer> list = new ArrayList<>();
Arrays.sort(candidates);
helper(candidates, rst, list, target, 0);
return rst;
}

private void helper(int[] candidates, List<List<Integer>> rst, List<Integer> list,
int left, int pos) {
if (left == 0) {
return;
}

for (int i = pos; i < candidates.length; i++) {
if (left - candidates[i] < 0) {
break;
}
helper(candidates, rst, list, left - candidates[i], i);
list.remove(list.size() - 1);
}
}
}


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

2016-04-10 23:42:47

LeetCode39:Combination Sum

2015-07-06 20:58:02

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

2017-01-31 16:47:37

377. Combination Sum IV-动态规划

2016-09-22 19:54:56

leetcode笔记：Combination Sum

2015-11-25 23:59:24

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

2016-06-16 17:01:20

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

2016-03-15 17:37:26

[LeetCode39]Combination Sum

2014-06-17 04:15:23

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

2016-07-26 13:38:06

【LeetCode】Combination Sum I & II 解题报告

2014-12-16 11:06:12

不良信息举报

[刷题]Combination Sum