国产探花免费观看_亚洲丰满少妇自慰呻吟_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();			}	}};


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 祥云县| 吴江市| 灵宝市| 富顺县| 株洲市| 广东省| 绥化市| 屏东县| 保靖县| 右玉县| 永宁县| 门头沟区| 安吉县| 上林县| 翁牛特旗| 寿阳县| 黑龙江省| 新河县| 荣成市| 巴林左旗| 安义县| 呼伦贝尔市| 临夏县| 奉贤区| 彰化县| 奉新县| 毕节市| 民丰县| 玛多县| 嘉义县| 海城市| 河池市| 荆州市| 高尔夫| 于田县| 视频| 邳州市| 大方县| 班戈县| 改则县| 玉门市|