LeetCode #40: Combination Sum II
来源:互联网 发布:java 时间戳长度 编辑:程序博客网 时间:2024/05/21 17:11
Problem Statement
(Source) 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]]
Solution
class Solution(object): def bt(self, candidates, target, res, ass, start_index): if target == 0: res.add(tuple(ass)) else: for index in xrange(start_index, len(candidates)): if candidates[index] > target: break ass.append(candidates[index]) self.bt(candidates, target - candidates[index], res, ass, index + 1) ass.pop() def combinationSum2(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ candidates.sort() res = set() self.bt(candidates, target, res, [], 0) return [list(x) for x in res]
0 0
- LeetCode(40) Combination Sum II
- [leetcode 40] Combination Sum II
- leetcode || 40、Combination Sum II
- leetcode 40: Combination Sum II
- Leetcode #40 Combination Sum II
- LeetCode(40) Combination Sum II
- LeetCode-40 Combination Sum II
- LeetCode 40: Combination Sum II
- leetcode 40:Combination Sum II
- Leetcode 40 - Combination Sum II
- 【leetcode】【40】Combination Sum II
- LeetCode 40 - Combination Sum II
- LeetCode(40)-Combination Sum II
- 【LeetCode-40】Combination Sum II
- LeetCode 40 Combination Sum II
- LeetCode-40:Combination Sum II
- Leetcode 40 Combination Sum II
- LeetCode #40: Combination Sum II
- java filter
- swustoj Locker doors(0480)
- 如何快速的开发一个完整的iOS直播app(播放篇)
- cmake的使用(cmake不是内部或外部命令)
- logstash对于String类型的时间转成long
- LeetCode #40: Combination Sum II
- 设置centos的YUM源为国内阿里云源
- 十四章上机练习四
- MFC窗口程序显示命令行输出窗口的方法
- 针对bootstrap没有多级导航栏的解决办法
- java排序之插入排序
- dSYM,app,crash 文件 UUID 匹配
- android recycleView使用总结
- 从零开始学 Java – Spring MVC 统一异常处理