标签:void http com solution div get sum htm 优化
https://www.cnblogs.com/grandyang/p/6395843.html
利用dfs的搜索把所有可能的情况找出来,然后判断。
此题还可以进一步优化
class Solution { public: int findTargetSumWays(vector<int>& nums, int S) { findTarget(nums,0,0,S); return res; } void findTarget(vector<int>& nums,int index,int sum,int S){ if(index == nums.size()){ if(sum == S) res++; return; } findTarget(nums,index+1,sum + nums[index],S); findTarget(nums,index+1,sum - nums[index],S); } int res = 0; };
标签:void http com solution div get sum htm 优化
原文地址:https://www.cnblogs.com/ymjyqsx/p/10497414.html