CombinationSumII { public List<List<Integer>> combinationSum2(int[] candidates, int target) { List<List<Integer>> result = new ArrayList<>(); Arrays.sort(candidates); int i = 0; while (i < candidates.length) { result.addAll(combinationTotarget(candidates, i, target)); int j = i + 1; while (j < candidates.length && candidates[j] == candidates[i]) { j++; } i = j; } return result; }  List<List<Integer>> combinationSum2(int[] candidates, int target);  }
@Test public void testRecursivePermutateNoDup() { int[] candidates = new int[]{10,1,2,7,6,1,5}; int target = 8; List<List<Integer>> expected = new ArrayList<>(); expected.add(Arrays.asList(1, 7)); expected.add(Arrays.asList(1, 2, 5)); expected.add(Arrays.asList(2, 6)); expected.add(Arrays.asList(1, 1, 6)); assertEqualsWithoutOrder(new CombinationSumII().combinationSum2(candidates, target), expected); }