class Solution { public: int res=0; int findTargetSumWays(vector<int>& nums, int target) { DFS(nums,target,0,0); return res; } void DFS(vector<int>& nums,int target,int index,const int sum) { if(index==nums.size()) { if(sum==target) { res+=1; } return; } DFS(nums,target,index+1,sum+nums[index]); DFS(nums,target,index+1,sum-nums[index]); } };
TRANSLATE with x English TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget: Bing Webmaster Portal Back