package leetcode;

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

/**
 * https://leetcode.com/problems/combination-sum-ii/
 */
public class Problem40 {
    public List<List<Integer>> combinationSum2(int[] candidates, int target) {
        List<List<Integer>> result = new ArrayList<>();
        // TODO
        return result;
    }

    public static void main(String[] args) {
        Problem40 prob = new Problem40();
    }
}

@@ -33,40 +33,9 @@
 til.
-ArrayList;%0Aimport java.util.List
+*
 ;%0A%0A/
@@ -266,132 +266,1281 @@
     
-// TODO%0A        return result;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem40 prob = new Problem40();
+Arrays.sort(candidates);%0A        List%3CInteger%3E candidateList = new ArrayList();%0A        for (int candidate : candidates) %7B%0A            candidateList.add(candidate);%0A        %7D%0A        List%3CInteger%3E accu = new ArrayList%3C%3E();%0A        combination(candidateList, target, 0, 0, accu, result);%0A        return result;%0A    %7D%0A%0A    private void combination(List%3CInteger%3E candidateList, int target, int idx, int sum,%0A                             List%3CInteger%3E accu, List%3CList%3CInteger%3E%3E result) %7B%0A        if (sum == target) %7B%0A            result.add(accu);%0A            return;%0A        %7D%0A        if (sum %3E target) %7B%0A            return;%0A        %7D%0A        for (int i = idx; i %3C candidateList.size(); i++) %7B%0A            List%3CInteger%3E newList = candidateList.subList(i, candidateList.size());%0A            List%3CInteger%3E newAccu = new ArrayList%3C%3E(accu);%0A            int val = candidateList.get(i);%0A            newAccu.add(val);%0A            combination(newList, target, idx+1, sum+val, newAccu, result);%0A%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem40 prob = new Problem40();%0A        List%3CList%3CInteger%3E%3E result = prob.combinationSum2(new int%5B%5D%7B10, 1, 2, 7, 6, 1, 5%7D, 8);%0A        for (List%3CInteger%3E list : result) %7B%0A            System.out.println(list);%0A        %7D
 %0A   

Update problem 40