思路展示 示例代码 登录后复制 class Solution { public: int res=0; void backtrack(vector<int>& nums, int target,int index,int sum){ if(index>=nums.size()){ if(sum==target){ res++; } return; } backtrack(nums,target,index+1,sum+nums[index]); backtrack(nums,target,index+1,sum-nums[index]); } int findTargetSumWays(vector<int>& nums, int target) { backtrack(nums,target,0,0); return res; } }; 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20. 效果展示 原创作者: u_15305087 转载于: https://blog.51cto.com/u_15305087/11773156