赞
踩
class Solution { public List<List<Integer>> combinationSum(int[] candidates, int target) { ArrayList<List<Integer>> res=new ArrayList<>(); if(candidates==null||candidates.length==0){ return res; } helper(res,new ArrayList<Integer>(),candidates,target,0); return res; } private void helper(ArrayList<List<Integer>> res,ArrayList<Integer> list,int[] candidates,int target,int start){ if(target==0){ res.add(new ArrayList(list)); return; } if(target<0){ return; } for(int i=start;i<candidates.length;i++){ list.add(candidates[i]); helper(res,list,candidates,target-candidates[i],i); list.remove(list.size()-1); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。