国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

LeetCode 40. Combination Sum II

2019-11-08 02:50:34
字體:
來源:轉載
供稿:網友

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();			}		}	}};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安仁县| 宁化县| 香格里拉县| 清河县| 婺源县| 阜康市| 齐河县| 布拖县| 灵宝市| 疏附县| 瓮安县| 长寿区| 长垣县| 阿图什市| 威海市| 乌兰浩特市| 温泉县| 蒙自县| 抚宁县| 灯塔市| 寿光市| 和龙市| 儋州市| 邢台市| 融水| 岱山县| 汪清县| 红桥区| 德格县| 正宁县| 吉安市| 嘉祥县| 六盘水市| 石棉县| 佛坪县| 中山市| 龙门县| 葫芦岛市| 龙泉市| 海安县| 宁国市|