@@ -0,0 +1,1425 @@
+package problems;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0Apublic class CombinationSum2 %7B%0A    public List%3CList%3CInteger%3E%3E combinationSum2(int%5B%5D num, int target) %7B%0A        if (num.length == 0)%0A            return new ArrayList%3CList%3CInteger%3E%3E();%0A%0A        Arrays.sort(num);%0A        return allCombinations(num, 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        if (A%5Bidx%5D %3E target)%0A            return out;%0A        if (A%5Bidx%5D == target) %7B%0A            List%3CInteger%3E list = new ArrayList%3CInteger%3E();%0A            list.add(A%5Bidx%5D);%0A            out.add(list);%0A            return out;%0A        %7D%0A%0A        if (idx %3C A.length - 1) %7B%0A            List%3CList%3CInteger%3E%3E re = allCombinations(A, idx + 1, target - A%5Bidx%5D);%0A            for (List%3CInteger%3E s : re)%0A                s.add(0, A%5Bidx%5D);%0A            out.addAll(re);%0A        %7D%0A        for (int i = idx + 1; i %3C A.length; i++) %7B%0A            if (A%5Bi%5D != A%5Bidx%5D) %7B%0A                out.addAll(allCombinations(A, i, target));%0A                break;%0A            %7D%0A        %7D%0A        return out;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        CombinationSum2 cs = new CombinationSum2();%0A%0A        int%5B%5D candidates = %7B 2, 3, 3, 7, 4 %7D;%0A        int target = 7;%0A        System.out.println(cs.combinationSum2(candidates, target));%0A    %7D%0A%7D%0A

Add Combination Sum 2