题目
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题,只不过不能重复选元素,而且给定的集合中有重复的元素,这个涉及到了列表中包含列表的去重问题
我的解法同39题,只是将其中每次递归时的i增加了
第二遍 java实现
python实现
|
|
Java实现
注意对重复元素的处理,当前for循环中如果再次遍历到相同的元素需要跳过
|
|
下面是discuss上的解法,虽然一样,但是比我的要简洁
|
|