public class Solution {
public List<List<Integer>> combinationSum2(int[] candidates, int target) {
List<List<Integer>> list = new ArrayList<>();
Arrays.sort(candidates);
helper(list, new ArrayList<>(), candidates, target, 0);
return list;
}
private void helper(List<List<Integer>> list, List<Integer> temp, int[] candidates, int remain, int start){
if(remain == 0){
if(!list.contains(temp)){
list.add(new ArrayList<>(temp));
}
return;
}
if(remain < 0){
return;
}
for(int i = start; i < candidates.length; i++){
temp.add(candidates[i]);
helper(list, temp, candidates, remain - candidates[i], i + 1);
temp.remove(temp.size() - 1);
}
}
}
[LeetCode] 40. Combination Sum II
最新推荐文章于 2017-03-31 11:39:00 发布