// 既然不能重复利用,就在递归中选择下一个数,不能重复的话,就用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的更多相关文章

  1. [array] leetcode - 40. Combination Sum II - Medium

    leetcode - 40. Combination Sum II - Medium descrition Given a collection of candidate numbers (C) an ...

  2. leetcode 39 dfs leetcode 40 dfs

    leetcode 39 先排序,然后dfs 注意先整全局变量可以减少空间利用 class Solution { vector<vector<int>>ret; vector&l ...

  3. [LeetCode] 40. Combination Sum II 组合之和之二

    Given a collection of candidate numbers (candidates) and a target number (target), find all unique c ...

  4. Java实现 LeetCode 40 组合总和 II(二)

    40. 组合总和 II 给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的每个数字在 ...

  5. Leetcode 40. Combination Sum II

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

  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]组合数和II Combination Sum II

    [题目] Given a collection of candidate numbers (candidates) and a target number (target), find all uni ...

  8. [leetcode]40. Combination Sum II组合之和之二

    Given a collection of candidate numbers (candidates) and a target number (target), find all unique c ...

  9. LeetCode 40 Combination Sum II(数组中求和等于target的所有组合)

    题目链接:https://leetcode.com/problems/combination-sum-ii/?tab=Description   给定数组,数组中的元素均为正数,target也是正数. ...

  10. [LeetCode] 40. Combination Sum II 组合之和 II

    Given a collection of candidate numbers (candidates) and a target number (target), find all unique c ...

随机推荐

  1. ubuntu16.04下安装opencv-3.1.0及其扩展模块opencv_contrib

    步骤1.安装依赖项 sudo apt--dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 可选的 sudo apt--dev l ...

  2. throw and throws in Java

    throw and throws in Java - GeeksforGeeks https://www.geeksforgeeks.org/throw-throws-java/ throw and ...

  3. Apache 2.4 编码GB2312中文乱码的问题

    今天部署了一个项目,代码和数据库都是gb2312的,本地和服务器都是apache2.4的版本,本地编码没问题,response的content-type是空的.按html的mete解析的,查看源码也是 ...

  4. SVN跨版本库迁移目录并保留提交日志

    现在有一份代码code在版本库reposA/dirB/下,现在想把它移动到reposB/dirAA/下,本来打算交给SA做,没想到SA似乎 也不太懂的样子.于是,自己在VPS搭建了一个svnserve ...

  5. 自动化工具构建vue项目

    其实之前对vue的话也有过一段时间的学习,博客园也是写了5篇vue的学习笔记.但是一直是通过CDN的方式在html文件头部引入vue.js,然后实例化vue对象绑定Dom,写组件写方法.就算是在实际项 ...

  6. 11.Git分支管理

    分支就是科幻电影里面的平行宇宙,当你正在电脑前努力学习Git的时候,另一个你正在另一个平行宇宙里努力学习SVN. 如果两个平行宇宙互不干扰,那对现在的你也没啥影响.不过,在某个时间点,两个平行宇宙合并 ...

  7. HDU1556:Color the ball(简单的线段树区域更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1556 Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定 ...

  8. vmware克隆虚拟机

    克隆步骤 右键需要克隆的虚拟机 > 管理,在克隆向导中选择完整克隆. 实验环境:win10_64bit + vmware 12 pro + CentOS6.9_64bit 克隆之后网络配置 克隆 ...

  9. [华为]输入n个整数,输出其中最小的k个

    链接:https://www.nowcoder.com/questionTerminal/69ef2267aafd4d52b250a272fd27052c来源:牛客网 输入n个整数,输出其中最小的k个 ...

  10. idea中使用插件lombok简化java bean的getter/setter/log等常用功能

    一.安装. 1. 2. 3. 4. . 二.使用 1. 2. 3. 结果分析,如果没有添加@Setter注解,则LombokTest中的student示例无法使用setAge()等方法.使用lombo ...