logs targe span can urn size list blog ray
- public class Solution {
- public List<List<Integer>> combinationSum(int[] candidates, int target) {
- List<List<Integer>> ret=new ArrayList<List<Integer>>();
- Arrays.sort(candidates);
- generateCombination(new ArrayList<Integer>(), 0, ret, candidates, target);
- return ret;
- }
- private void generateCombination(List<Integer> list, int idx, List<List<Integer>> combs, int[] candidates, int target){
- if(target==0)
- {
- combs.add(new ArrayList<Integer>(list));
- return;
- }
- if(target<0||idx>=candidates.length)
- return;
- generateCombination(list, idx+1, combs, candidates, target);
- list.add(candidates[idx]);
- generateCombination(list, idx, combs, candidates, target-candidates[idx]);
- list.remove(list.size()-1);
- }
- }
39. Combination Sum
来源: http://www.bubuko.com/infodetail-2322572.html