class Solution
{
private List<List<Integer>> results = new ArrayList<>();
public List<List<Integer>> combinationSum2(int[] candidates, int target)
{
Arrays.sort(candidates);
dfs(candidates, target, 0, new ArrayList<Integer>());
return results;
}
public void dfs(int[] candidates, int target, int i, List<Integer> temp)
{
if(target == 0)
{
results.add(new ArrayList(temp));
return;
}
for(int j = i; j < candidates.length; j++)
{
if(j > i && candidates[j] == candidates[j - 1] ) continue;
if(target < candidates[j])
{
break;
}
temp.add(candidates[j]);
dfs(candidates, target - candidates[j], j + 1, temp);
temp.remove(temp.size() - 1);
}
}
}