LeetCode 40
// 既然不能重复利用,就在递归中选择下一个数,不能重复的话,就用set
class Solution {
public:
vector<vector<int>> combinationSum2(vector<int>& candidates, int target) {
set<vector<int>> res;
sort(candidates.begin(),candidates.end());
vector<int> add;
DFS(candidates,target,,add,res);
return vector<vector<int>>(res.begin(),res.end()); }
void DFS(vector<int>& candidates, int target,int start,vector<int>& add,set<vector<int>>& res){
if(target < )return;
else if(target == ){res.insert(add);}
else{
for(int i=start;i < candidates.size();i++){
add.push_back(candidates[i]);
DFS(candidates,target-candidates[i],i+,add,res);
add.pop_back();
}
}
}
};
LeetCode 40的更多相关文章
- [array] leetcode - 40. Combination Sum II - Medium
leetcode - 40. Combination Sum II - Medium descrition Given a collection of candidate numbers (C) an ...
- leetcode 39 dfs leetcode 40 dfs
leetcode 39 先排序,然后dfs 注意先整全局变量可以减少空间利用 class Solution { vector<vector<int>>ret; vector&l ...
- [LeetCode] 40. Combination Sum II 组合之和之二
Given a collection of candidate numbers (candidates) and a target number (target), find all unique c ...
- Java实现 LeetCode 40 组合总和 II(二)
40. 组合总和 II 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的每个数字在 ...
- Leetcode 40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- LeetCode 40. Combination Sum II (组合的和之二)
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...
- [Leetcode 40]组合数和II Combination Sum II
[题目] Given a collection of candidate numbers (candidates) and a target number (target), find all uni ...
- [leetcode]40. Combination Sum II组合之和之二
Given a collection of candidate numbers (candidates) and a target number (target), find all unique c ...
- LeetCode 40 Combination Sum II(数组中求和等于target的所有组合)
题目链接:https://leetcode.com/problems/combination-sum-ii/?tab=Description 给定数组,数组中的元素均为正数,target也是正数. ...
- [LeetCode] 40. Combination Sum II 组合之和 II
Given a collection of candidate numbers (candidates) and a target number (target), find all unique c ...
随机推荐
- expdp全库备份rac数据库因错误终止
1.expdp导出日志报错如下: ORA-39014: One or more workers have prematurely exited. ORA-39029: worker 2 with pr ...
- 通过IP获取对应所在地的地址
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wangshuxuncom/article/details/35988143 曾几何时 ...
- EasyUI Progressbar 进度条
通过 $.fn.progressbar.defaults 重写默认的 defaults. 进度条(progressbar)提供了一种显示长时间操作进度的反馈.进度可被更新以便让用户知道当前正在执行的操 ...
- [py][lc]python的纸牌知识点
模块collections-collections.namedtuple表示tuple 如表示一个坐标, t = (1,2), 搞不清楚. 如果这样就对了Point(x=1, y=2) from co ...
- java中string.trim()函数的作用
trim /[trɪm] / 英文意思:整理,修理,修剪,整齐的 trim()的作用:去掉字符串首尾的空格. public static void main(String arg[]){ Strin ...
- Singapore retailer will release this adidas NMD R1
Select spots are restocking the adidas NMD Singapore this Friday, Feb 24th featuring three different ...
- Linux系统——Ansible批量管理工具
批量管理工具: (1)ansible 操作简单(适用于500台以下服务器) (2)saltstack 比较复杂(一般适用于1000-4w台服务器) (3)puppet超级复杂 systemctl(统一 ...
- python中的排序
今天在http://www.pythontip.com刷题的时候遇到一个排序的问题:一个列表中既有字符串,又有数字,该怎么排序. list = [1,2,5,4,'d','s','e',45] lis ...
- 20155203 2016-2017-4 《Java程序设计》第8周学习总结
20155203 2016-2017-4 <Java程序设计>第8周学习总结 教材学习内容总结 1.channel的继承架构 2.position()类似于堆栈操作中的栈顶指针. 3.Pa ...
- JavaScript 预编译(变量提升和函数提升的原理)
本文部分内容转自https://www.cnblogs.com/CBDoctor/p/3745246.html 1.变量提升 console.log(global); // undefined var ...