Leetcode no. 39
来源:互联网 发布:mp4加速播放软件 编辑:程序博客网 时间:2024/04/29 12:57
39. 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[] candidates, int target) { List<List<Integer>> res= new LinkedList<List<Integer>>(); List<Integer> lis= new LinkedList<Integer>(); if (candidates.length== 0) return res; Arrays.sort(candidates); combinationSum(candidates, target, res, lis, 0); return res; } private void combinationSum(int[] candi, int target, List<List<Integer>> result, List<Integer> list, int start){ if (target==0) result.add(new LinkedList<>(list)); for (int i = start; i < candi.length; i++) { if (target < candi[i]) break; list.add(candi[i]); combinationSum(candi, target-candi[i], result, list, i); list.remove(list.size()-1); } }}
0 0
- Leetcode no. 39
- Leetcode NO.39 Combination Sum
- LeetCode No.11 ~No.12
- Leetcode NO.78 Subsets
- Leetcode NO.77 Combinations
- Leetcode NO.46 Permutations
- 【leetcode】No. 235 LCABST
- LeetCode no. 35
- Leetcode no. 37
- Leetcode no. 279
- Leetcode no. 335
- Leetcode no. 283
- Leetcode no. 181 (sql)
- Leetcode no. 40
- Leetcode no. 238
- Leetcode no. 26
- Leetcode no. 80
- Leetcode no. 228
- 指向函数的指针
- Dubbo安装部署
- poj2485 最小生成树 kruskal算法
- java泛型——基本使用
- Tyvj_P1010
- Leetcode no. 39
- spring security学习,使用过程
- 剑指offer系列之48:把字符串转换成整数
- Thinkphp笔记3 模型
- 模板:DINIC
- c++第三次上机实验
- C++作业3
- LeetCode *** 59. Spiral Matrix II
- CSS学习笔记(五):盒模式和内容格式化