40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
Each number in C may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
The solution set must not contain duplicate combinations.
For example, given candidate set [10, 1, 2, 7, 6, 1, 5] and target 8,
A solution set is:
[
[1, 7],
[1, 2, 5],
[2, 6],
[1, 1, 6]
]
题意:
题意同39. Combination Sum,不同点就是,给定的数组元素含有重复元素值,而且每个元素在组合数组中只能出现一次。
思路:
思路同39. Combination Sum,不同点就是,因为数组元素含有重复元素值,所以再递归的过程中,要进行判断,跳过重复元素。
1 | class Solution { |
Java Code:
1 | class Solution { |