g***j 发帖数: 1275 | 1 Combination Sum
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.
Elements in a combination must be in non-descending order.
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]
现在有几个结果过不去
比如
输入1,1, target 是 1 ,期待返回的结果应该是[[1]],但是我的程序返回的结果总
是[[1],[1]],
我开始以为把输入数据里面的重复去掉就行了,但是,根据测试集来看,输入的两个1
被当成两个不同的1,但是结果呢,[1] 和 [1] 又当成两个一样的1,请问如何解决这
个问题,这种重复如何在选的过程中去掉? 如果选完了再去掉重复,应该不好吧? | t********5 发帖数: 522 | | d**e 发帖数: 6098 | 3 输出结果用Set>可以解决吗?
【在 g***j 的大作中提到】 : Combination Sum : 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. : Elements in a combination must be in non-descending order. : 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:
| g***j 发帖数: 1275 | 4 要求返回vector >
当然用set应该可以,但是如果再dump到vector里面,感觉很ugly啊
【在 d**e 的大作中提到】 : 输出结果用Set>可以解决吗?
| d**e 发帖数: 6098 | 5 以前好像做过这题,因为结果要求是排序的,那么一开始先排序再算结果应该可以去掉重
复.
【在 g***j 的大作中提到】 : 要求返回vector > : 当然用set应该可以,但是如果再dump到vector里面,感觉很ugly啊
|
|