题目:

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.

 Example

Given candidate set [10,1,6,7,2,1,5] and target 8,

A solution set is:

[
[1,7],
[1,2,5],
[2,6],
[1,1,6]
]

题解:

  主要是去重复,多个方法,之前已经介绍过。利用set

Solution 1 ()

class Solution {
public:
vector<vector<int> > combinationSum2(vector<int> &num, int target) {
vector<vector<int> > res;
vector<int> cur;
sort(num.begin(), num.end());
dfs(res, cur, num, target, ); return res;
}
void dfs(vector<vector<int> > &res, vector<int> &cur, vector<int> &num, int target, int pos){
if (!num.empty() && target == ) {
res.push_back(cur);
return;
}
for (int i = pos; i < num.size(); ++i) {
if(i > pos && num[i] == num[i-]) {
continue;
}
if (target - num[i] >= ) {
cur.push_back(num[i]);
dfs(res, cur, num, target - num[i], i + );
cur.pop_back();
} else {
break;
}
}
}
};

【Lintcode】153.Combination Sum II的更多相关文章

  1. 【LeetCode】40. Combination Sum II (2 solutions)

    Combination Sum II Given a collection of candidate numbers (C) and a target number (T), find all uni ...

  2. 【LeetCode】40. Combination Sum II 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:DFS 方法二:回溯法 日期 题目地址:ht ...

  3. 【LeetCode】040. Combination Sum II

    题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...

  4. 【Lintcode】135.Combination Sum

    题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C  ...

  5. 【LeetCode】113. Path Sum II 解题报告(Python)

    [LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fu ...

  6. 【LeetCode题意分析&解答】40. Combination Sum II

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  7. 【一天一道LeetCode】#40. Combination Sum II

    一天一道LeetCode系列 (一)题目 Given a collection of candidate numbers (C) and a target number (T), find all u ...

  8. 【LeetCode】216. Combination Sum III

    Combination Sum III Find all possible combinations of k numbers that add up to a number n, given tha ...

  9. 【LeetCode】167. Two Sum II - Input array is sorted

    Difficulty:easy  More:[目录]LeetCode Java实现 Description Given an array of integers that is already sor ...

随机推荐

  1. 在tomcat中用jndi配置数据源启动java web程序

    1.在web.xml中添加: <resource-ref>    <res-ref-name>jdbc/MTSDB</res-ref-name>    <re ...

  2. andorid中发送短信页面以及邮件发送

    跳转到发送短信页面 Uri smsToUri = Uri.parse("smsto://10086"); Intent mIntent = new Intent( android. ...

  3. C市现在要转移一批罪犯到D市,C市有n名罪犯,按照入狱时间有顺序,另外每个罪犯有一个罪行值,值越大罪越重。现在为了方便管理,市长决定转移入狱时间连续的c名犯人,同时要求转移犯人的罪行值之和不超过t,问有多少种选择的方式?

    // ConsoleApplication12.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" // ConsoleApplication1 ...

  4. android 自定义控件View在Activity中使用findByViewId得到结果为null

    转载:http://blog.csdn.net/xiabing082/article/details/48781489 1.  大家常常自定义view,,然后在xml 中添加该view 组件..如果在 ...

  5. 百思不得姐之&quot;我的&quot;模块功能(六)

    一 功能图和知识点 1 功能图部分:(因为网速的原因,网页部分没有载入出来,可是功能完善) 2 该部分能学到的知识点概括: >1 UITableView的使用(简单) >2 UIColle ...

  6. COGS1532. [IOI2001]移动电话

    1532. [IOI2001]移动电话 ★☆   输入文件:mobilephones.in   输出文件:mobilephones.out   简单对比时间限制:5 s   内存限制:256 MB [ ...

  7. EasyDarwin支持GB28181协议开发

    本文转自:http://blog.csdn.net/gavin1010/article/details/77926853 EasyGB28181服务器开发 背景 当前的安防行业,除了私有协议,普遍使用 ...

  8. [Python]Pip换源以及设置代理

    Install python package with proxy sudo pip install python-magic --proxy=https://your-proxy.com 2.No ...

  9. 线程池ThreadPoolExcecutor介绍

    线程池ThreadPoolExecutor 使用Executors和ThreadPoolExecutor 并发新特性—Executor 框架与线程池

  10. Java for LeetCode 094 Binary Tree Inorder Traversal

    解题思路: 中序遍历,左子树-根节点-右子树 JAVA实现如下: public List<Integer> inorderTraversal(TreeNode root) { List&l ...