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

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

LeetCode 39. Combination Sum

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

Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.

The same repeated number may be chosen from C unlimited number of times.

Note:

All numbers (including target) will be positive integers.The solution set must not contain duplicate combinations.

For example, given candidate set [2, 3, 6, 7] and target 7, A solution set is: 

[  [7],  [2, 2, 3]]answer:

class Solution {public:	vector<vector<int>> combinationSum(vector<int>& candidates, int target) {		vector<int> temp;		vector<vector<int>> result;		myCombine(candidates,target,0,temp,result);		return result;	}	void myCombine(vector<int>& candidates, int target,int index,vector<int> & temp, vector<vector<int>> & result){		if(target < 0){			return;		}		if(0 == target){			result.push_back(temp);			return;		}//		sum += candidates[index];			for(int i = index; i < candidates.size(); i ++){				temp.push_back(candidates[i]);				myCombine(candidates,target - candidates[i],i,temp,result);				temp.pop_back();			}	}};


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 文登市| 东阿县| 德格县| 宁国市| 天全县| 浙江省| 斗六市| 巴南区| 新巴尔虎左旗| 黄浦区| 顺义区| 肇源县| 五大连池市| 蕲春县| 黎川县| 仪征市| 镇赉县| 买车| 新兴县| 宜春市| 康平县| 邻水| 乌海市| 翁源县| 军事| 江北区| 运城市| 成安县| 盖州市| 沁水县| 睢宁县| 互助| 江华| 阿城市| 文化| 高青县| 防城港市| 神池县| 都安| 万全县| 镶黄旗|