题解 | #加起来和为目标值的组合(四)#
加起来和为目标值的组合(四)
https://www.nowcoder.com/practice/7a64b6a6cf2e4e88a0a73af0a967a82b
class Solution { public: int sum = 0; void dfs(vector<int>& nums, int cur,int target) { if(cur>target) return; if(cur==target) { sum++; return; } for(int i = 0;i<nums.size();i++) { dfs(nums, cur+nums[i], target); } } int combination(vector<int>& nums, int target) { // write code here dfs(nums, 0, target); return sum; } };