题目:

Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.

The same repeated number may be chosen from C unlimited number of times.

Note:

  • All numbers (including target) will be positive integers.
  • The solution set must not contain duplicate combinations.

For example, given candidate set [2, 3, 6, 7] and target 7
A solution set is:

[
[7],
[2, 2, 3]
]

  

题解:

Solution 1 ()

class Solution {
public:
void dfs(vector<vector<int>>& vv, vector<int>& v, vector<int> candidates, int target, int sum) {
if(sum == target) {
vector<int>* tmp = new vector<int>;
*tmp = v;
sort((*tmp).begin(), (*tmp).end());
if(find(vv.begin(), vv.end(), *tmp) == vv.end())
vv.push_back(*tmp);
delete tmp;
return;
}
if(sum > target) return;
for(int i=; i<candidates.size(); ++i) {
v.push_back(candidates[i]);
dfs(vv, v, candidates, target, sum+candidates[i]);
v.pop_back();
}
}
vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
vector<vector<int>> vv;
vector<int> v;
dfs(vv, v, candidates, target, );
return vv;
}
};

最新文章

  1. 【六年开源路】FineUI家族今日全部更新!
  2. Elasticsearch——Date Math在索引中的用法详解
  3. 编写一个Java应用程序,该应用程序包括2个类:Print类和主类E。Print 类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的 立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来 测试类Print
  4. 面对一个新的MCU,我再也不敢说第一步是点灯了
  5. Multiverse in Doctor Strange // Multiverse在《神秘博士》
  6. Android 学习笔记之Volley(八)实现网络图片的数据加载
  7. Unity制作FPS Demo
  8. jQuery的deferred对象
  9. Android 开发中常用 ADB 命令总结
  10. threading event
  11. Python成长之路第二篇(2)_列表元组内置函数用法
  12. C++ 前置声明 和 包含头文件 如何选择
  13. leetcode第十题--Regular Expression Matching
  14. JPA 系列教程17-继承-独立表-TABLE_PER_CLASS
  15. Eclipse的Console乱码
  16. Unity User Group 北京站:《Unity5.6新功能介绍以及HoloLens开发》
  17. python 有关datetime时间日期 以及时间戳转换
  18. 深入Java虚拟机(4)——网络移动性
  19. kmeans算法思想及其python实现
  20. ttribute &quot;xmlns&quot; was already specified for element &quot;web-app&quot;.

热门文章

  1. substring,subsequence,charAt执行效率的不同
  2. 李振杰:火狐Mozilla被黑事件的启发
  3. 基于IAP和网口升级固件
  4. lucene分词器中的Analyzer,TokenStream, Tokenizer, TokenFilter
  5. 深入Asyncio(十)异步解析式
  6. PowerBuilder -- 结构类型(structure)
  7. EasyPlayerPro(Windows)流媒体播放器功能介绍及应用场景
  8. mac sublime text 3 add ctags plugin
  9. Locality-sensitive hashing Pr[m(Si) = m(Sj )] = E[JSˆ (Si, Sj )] = JS(Si, Sj )
  10. 销售订单增强字段 bapi更新