leetcode
来源:互联网 发布:linux安装oracle 编辑:程序博客网 时间:2024/06/10 22:33
Combination Sum II
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.
Note:
- All numbers (including target) will be positive integers.
- The solution set must not contain duplicate combinations.
For example, given candidate set [10, 1, 2, 7, 6, 1, 5]
and target 8
,
A solution set is:
[ [1, 7], [1, 2, 5], [2, 6], [1, 1, 6]]
class Solution {public: vector<vector<int>> combinationSum2(vector<int>& candidates, int target) { vector<int> out; vector<vector<int> > res; sort(candidates.begin(),candidates.end()); combinationSum2DFS(candidates,target,out,0,res); return res; } void combinationSum2DFS(vector<int>& candidates,int target,vector<int>& out,int start,vector<vector<int> >&res) { if(target<0) return; else if(target == 0) res.push_back(out); else { for(int i=start;i<candidates.size();i++) { if(i>start && candidates[i]==candidates[i-1]) continue; out.push_back(candidates[i]); combinationSum2DFS(candidates,target-candidates[i],out,i+1,res); out.pop_back(); } } }};
阅读全文
0 0
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- linux下编程实现GPS数据获取与解析
- 深入学习Hibernate4_07使用二级缓存
- caffe:网络结构可视化工具
- mysql插入操作中旧数据处理(ignore和on duplicate key update)
- php的9种魔术方法
- leetcode
- SheetJS/js-xlsx的小demo
- MySQL完全卸载及免安装MySQL的启动
- HTTP 1.1 400 Bad Request 11ms
- spring和springMVC
- 后端只要逻辑不管体验
- servlet监听器
- the host name "linux-xxxx" is invalid
- MVC model验证