由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 关于结果除掉重复的问题请教
相关主题
问道leetcode的题:Combination Sum II问一道leetcode上的题目 combination sum
请教leetcode Combination Sum II的code,谢谢。做题
Combination Sum II哪里做错了A家的题
一个小题 谁能帮着给点思路 谢谢啦!求教 leetcode上OJ 的Combination Sum II 解法
a problem from leetcode: high efficiency algorithm for combinations problema question about combination
Combination Sum 时间和空间复杂度是多少?这题也可以DP 解吧?
combination sum IICS: print all combination from an array
发个Palantir的电面,并求g家onsite的blessgenerate unique integer ID from columns in SQL table
相关话题的讨论汇总
话题: 结果话题: target话题: set话题: 重复
进入JobHunting版参与讨论
1 (共1页)
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
2
看错题了。。。 默默的改掉。。。
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啊

1 (共1页)
进入JobHunting版参与讨论
相关主题
generate unique integer ID from columns in SQL tablea problem from leetcode: high efficiency algorithm for combinations problem
一FG家常见题Combination Sum 时间和空间复杂度是多少?
combinations 有没有 iterative的方法阿 ?combination sum II
问个递归的问题发个Palantir的电面,并求g家onsite的bless
问道leetcode的题:Combination Sum II问一道leetcode上的题目 combination sum
请教leetcode Combination Sum II的code,谢谢。做题
Combination Sum II哪里做错了A家的题
一个小题 谁能帮着给点思路 谢谢啦!求教 leetcode上OJ 的Combination Sum II 解法
相关话题的讨论汇总
话题: 结果话题: target话题: set话题: 重复