@@ -0,0 +1,1317 @@
+package problems;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Apublic class CombinationSum %7B%0A    public List%3CList%3CInteger%3E%3E combinationSum(int%5B%5D candidates, int target) %7B%0A        if (candidates.length == 0)%0A            return new ArrayList%3CList%3CInteger%3E%3E();%0A%0A        Arrays.sort(candidates);%0A        return allCombinations(candidates, 0, target);%0A    %7D%0A%0A    List%3CList%3CInteger%3E%3E allCombinations(int%5B%5D A, int idx, int target) %7B%0A        List%3CList%3CInteger%3E%3E out = new ArrayList%3CList%3CInteger%3E%3E();%0A        int sum = 0;%0A        List%3CInteger%3E list = new ArrayList%3CInteger%3E();%0A        while (sum %3C= target) %7B%0A            if (sum == target)%0A                out.add(list);%0A            else if (idx %3C A.length - 1) %7B%0A                List%3CList%3CInteger%3E%3E re = allCombinations(A, idx + 1, target - sum);%0A                for (List%3CInteger%3E a : re)%0A                    a.addAll(0, list);%0A                out.addAll(re);%0A            %7D%0A            sum += A%5Bidx%5D;%0A            if (sum %3C= target)%0A                list.add(A%5Bidx%5D);%0A        %7D%0A        return out;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        CombinationSum cs = new CombinationSum();%0A%0A        int%5B%5D candidates = %7B 2, 3, 7, 4 %7D;%0A        int target = 7;%0A        System.out.println(cs.combinationSum(candidates, target));%0A    %7D%0A%7D%0A

Add Combination Sum