# 组合总和 II

给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。

candidates 中的每个数字在每个组合中只能使用一次。

说明:

示例 1:

输入: candidates = [10,1,2,7,6,1,5], target = 8,
所求解集为:
[[1, 7],[1, 2, 5],[2, 6],[1, 1, 6]]

示例 2:

输入: candidates = [2,5,2,1,2], target = 5,
所求解集为:
[[1,2,2],[5]]
## template ```java class Solution { public List> combinationSum2(int[] candidates, int target) { Arrays.sort(candidates); List> res = new ArrayList>(); if (candidates.length == 0 || target < candidates[0]) return res; List tmp = new ArrayList(); helper(candidates, target, 0, tmp, res); return res; } public void helper(int[] a, int target, int start, List tmp, List> res) { if (target < 0) return; if (target == 0) { res.add(new ArrayList(tmp)); return; } for (int i = start; i < a.length; i++) { tmp.add(a[i]); int newtarget = target - a[i]; helper(a, newtarget, i + 1, tmp, res); tmp.remove(tmp.size() - 1); if (newtarget <= 0) break; while (i + 1 < a.length && a[i] == a[i + 1])// 组合中有重复元素,不要重复开头 i++; } } } ``` ## 答案 ```java ``` ## 选项 ### A ```java ``` ### B ```java ``` ### C ```java ```