```
class Solution {
private:
int dfs(vector<int>& nums,int S,int i){
if( i==nums.size() ) return S==0;
return dfs(nums,S-nums[i],i+1)+dfs(nums,S+nums[i],i+1);
}
public:
int findTargetSumWays(vector<int>& nums, int S) {
return dfs(nums,S,0);
}
};
```