494目标和 DFS回溯

494目标和 DFS回溯

 

 

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
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
494目标和 DFS回溯 494目标和 DFS回溯 494目标和 DFS回溯 494目标和 DFS回溯   TRANSLATE with 494目标和 DFS回溯 COPY THE URL BELOW 494目标和 DFS回溯 494目标和 DFS回溯 Back EMBED THE SNIPPET BELOW IN YOUR SITE 494目标和 DFS回溯 Enable collaborative features and customize widget: Bing Webmaster Portal Back
上一篇:【DB笔试面试494】Oracle中哪个包用于生成随机值?


下一篇:字符串题目:破坏回文串