LeetCode 40. Combination Sum II
来源:互联网 发布:断网软件下载 编辑:程序博客网 时间:2024/05/11 05:47
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) {sort(candidates.begin(),candidates.end());vector<int> temp;vector<vector<int>> result;myComb2(candidates,target,0,temp,result);return result;}void myComb2(vector<int>& candidates, int target,int index,vector<int> & temp,vector<vector<int>> & result){// if(target < 0) return;if(target == 0){// temp.push_back(candidates[index]);result.push_back(temp);return;}for(int i = index; i < candidates.size() && target >= candidates[i]; i ++){if((i == index) || (candidates[i] != candidates[i - 1])){temp.push_back(candidates[i]);myComb2(candidates,target - candidates[i],i + 1,temp,result);temp.pop_back();}}}};
0 0
- [LeetCode]40.Combination Sum II
- LeetCode --- 40. Combination Sum II
- LeetCode 40.Combination Sum II
- [Leetcode] 40. Combination Sum II
- LeetCode 40. Combination Sum II
- [leetcode] 40. Combination Sum II
- 40. Combination Sum II LeetCode
- leetcode 40. Combination Sum II
- Leetcode 40. Combination Sum II
- LeetCode 40. Combination Sum II
- leetcode 40. Combination Sum II
- LeetCode 40. Combination Sum II
- LeetCode 40. Combination Sum II
- LeetCode *** 40. Combination Sum II
- 【LeetCode】40. Combination Sum II
- leetcode 40. Combination Sum II
- LeetCode - 40. Combination Sum II
- [LeetCode] 40. Combination Sum II
- 网站SEO
- 【java中文编码】深入分析java中的中文编码问题
- 华为OJ——字符串逆序
- Hibernate中的持久化类
- iOS中协议delegate的传值注意点
- LeetCode 40. Combination Sum II
- Struts2系列笔记(4)---Ation类访问servle
- 修改Linux内核的printk缓冲区(log缓冲区)大小
- [省选] [期望DP] [HLOI2016] 小明的智力游戏
- spring学习随笔4
- 【spoj】【COT2 - Count on a tree II】【莫队算法】
- 【SpringBoot】SpringBoot核心-外部配置
- C++ 多态 虚函数 通用链表用c++多态实现(不用模板)
- 无锁有序链表的实现