More typical helper topics, and now I'm not quite clear about DFS and so on, can only use helper to collectively, you know that tune on the line
Public classSolution { PublicArraylist<arraylist<integer>> Combinationsum (int[] candidates,inttarget) {ArrayList<ArrayList<Integer>> res =NewArraylist<arraylist<integer>>(); Arrays.sort (candidates); if(Candidates = =NULL|| CANDIDATES.LENGTH<1)returnRes; Helper (candidates, target, RES,NewArraylist<integer> (), 0); returnRes; } Public voidHelperint[] C,intt,arraylist<arraylist<integer>> Res, arraylist<integer> item,intstart) { if(0==t) {Res.add (NewArraylist<integer> (item));//Res.add (item); return;//Speed } if(0>t)return; for(intI=start; i< c.length; i++){ if(I>start && C[i-1]==c[i])Continue; Item.add (C[i]); Helper (c, T-c[i], res, item, i);//If I becomes i+1, then the repetition element is not allowed to appear, and I, and the loop starts from I=start, allows the possibility of repeating elements to build the target, and resolves the IIItem.remove (Item.size ()-1); } }}
Combination Sum I and II