标签:sum tor ++ bsp style ati oid target tar
1 class Solution 2 { 3 vector<vector<int>> res; 4 int sum = 0; 5 public: 6 void helper(vector<int>& nums, int start,int target, vector<int>& out) 7 { 8 if(sum == target) 9 { 10 res.push_back(out); 11 } 12 13 if(sum > target) return; 14 15 for (int i = start; i < nums.size(); ++i) 16 { 17 out.push_back(nums[i]); 18 sum += nums[i]; 19 helper(nums, i,target,out);// 数字可以无限制重复被选取,所以是i 20 21 out.pop_back(); 22 sum -= nums[i]; 23 } 24 } 25 26 vector<vector<int>> combinationSum(vector<int>& nums, int target) 27 { 28 vector<int> out; 29 helper(nums,0,target,out); 30 return res; 31 } 32 };
标签:sum tor ++ bsp style ati oid target tar
原文地址:https://www.cnblogs.com/yuhong1103/p/12514425.html