public class Solution {
public List<List<Integer>> combinationSum2(int[] candidates, int target) {
List<Integer> path = new ArrayList<Integer>();
List<List<Integer>> rst = new ArrayList(path);
if (candidates == null || candidates.length == 0) {
return rst;
}
Arrays.sort(candidates);
helper(candidates, target, 0, path, rst);
return rst;
}
private void helper(int[] candidates, int target, int pos, List<Integer> path, List<List<Integer>> rst) {
if (target < 0) {
return;
}
if (target == 0) {
rst.add(new ArrayList(path));
return;
}
for (int i = pos; i < candidates.length; i++) {
path.add(candidates[i]);
helper(candidates, target - candidates[i], i + 1, path, rst);
path.remove(path.size() - 1);
while (i < candidates.length - 1 && candidates[i] == candidates[i + 1]) i++;
}
}
}