package leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * https://leetcode.com/problems/combination-sum/
 */
public class Problem39 {
    public List<List<Integer>> combinationSum(int[] candidates, int target) {
        List<List<Integer>> result = new ArrayList<>();
        // TODO: implement this
        return result;
    }
    
    public static void main(String[] args) {
        Problem39 prob = new Problem39();
        for (List<Integer> list : prob.combinationSum(new int[]{2, 3, 6, 7}, 7)) {
            System.out.println(list);
        }
    }
}

@@ -57,19 +57,97 @@
 va.util.
-Lis
+Collections;%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Se
 t;%0A%0A/**%0A
@@ -371,31 +371,198 @@
     
-// TODO: implement this
+Set%3CList%3CInteger%3E%3E set = new HashSet%3C%3E();%0A        combinationSum(candidates, target, new ArrayList%3C%3E(), set);%0A        for (List%3CInteger%3E list : set) %7B%0A            result.add(list);%0A        %7D
 %0A   
@@ -601,207 +601,533 @@
    p
-ublic static void main(String%5B%5D args) %7B%0A        Problem39 prob = new Problem39();%0A        for (List%3CInteger%3E list : prob.combinationSum(new int%5B%5D%7B2, 3, 6, 7%7D, 7)) %7B%0A            System.out.println(lis
+rivate void combinationSum(int%5B%5D candidates, int target, List%3CInteger%3E accu,%0A        Set%3CList%3CInteger%3E%3E result) %7B%0A        if (target == 0) %7B%0A            Collections.sort(accu);%0A            result.add(accu);%0A            return;%0A        %7D    %0A        if (target %3C 0) %7B%0A            return;%0A        %7D%0A        for (int i = 0; i %3C candidates.length; i++) %7B%0A            List%3CInteger%3E newAccu = new ArrayList%3C%3E(accu);%0A            newAccu.add(candidates%5Bi%5D);%0A            combinationSum(candidates, target-candidates%5Bi%5D, newAccu, resul
 t);%0A

Solve problem 39