【LeetCode】039. Combination Sum
2024-09-24 17:49:48
题目:
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;
}
};
最新文章
- 【六年开源路】FineUI家族今日全部更新!
- Elasticsearch——Date Math在索引中的用法详解
- 编写一个Java应用程序,该应用程序包括2个类:Print类和主类E。Print 类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的 立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来 测试类Print
- 面对一个新的MCU,我再也不敢说第一步是点灯了
- Multiverse in Doctor Strange // Multiverse在《神秘博士》
- Android 学习笔记之Volley(八)实现网络图片的数据加载
- Unity制作FPS Demo
- jQuery的deferred对象
- Android 开发中常用 ADB 命令总结
- threading event
- Python成长之路第二篇(2)_列表元组内置函数用法
- C++ 前置声明 和 包含头文件 如何选择
- leetcode第十题--Regular Expression Matching
- JPA 系列教程17-继承-独立表-TABLE_PER_CLASS
- Eclipse的Console乱码
- Unity User Group 北京站:《Unity5.6新功能介绍以及HoloLens开发》
- python 有关datetime时间日期 以及时间戳转换
- 深入Java虚拟机(4)——网络移动性
- kmeans算法思想及其python实现
- ttribute ";xmlns"; was already specified for element ";web-app";.
热门文章
- substring,subsequence,charAt执行效率的不同
- 李振杰:火狐Mozilla被黑事件的启发
- 基于IAP和网口升级固件
- lucene分词器中的Analyzer,TokenStream, Tokenizer, TokenFilter
- 深入Asyncio(十)异步解析式
- PowerBuilder -- 结构类型(structure)
- EasyPlayerPro(Windows)流媒体播放器功能介绍及应用场景
- mac sublime text 3 add ctags plugin
- Locality-sensitive hashing Pr[m(Si) = m(Sj )] = E[JSˆ (Si, Sj )] = JS(Si, Sj )
- 销售订单增强字段 bapi更新