a亚洲精品_精品国产91乱码一区二区三区_亚洲精品在线免费观看视频_欧美日韩亚洲国产综合_久久久久久久久久久成人_在线区

首頁 > 學院 > 開發設計 > 正文

[leetcode]494. Target Sum

2019-11-14 09:53:26
字體:
來源:轉載
供稿:網友

題目鏈接:https://leetcode.com/PRoblems/target-sum/

You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For each integer, you should choose one from + and - as its new symbol.

Find out how many ways to assign symbols to make sum of integers equal to target S.

Example 1:

Input: nums is [1, 1, 1, 1, 1], S is 3. Output: 5Explanation: -1+1+1+1+1 = 3+1-1+1+1+1 = 3+1+1-1+1+1 = 3+1+1+1-1+1 = 3+1+1+1+1-1 = 3There are 5 ways to assign symbols to make the sum of nums be target 3.

Note:

The length of the given array is positive and will not exceed 20.The sum of elements in the given array will not exceed 1000.Your output answer is guaranteed to be fitted in a 32-bit integer.

class Solution{public:    int findTargetSumWays(vector<int>& nums,int S)    {        int count=0;        dfs(nums,count,0,0,S);        return count;    }    void dfs(vector<int>& nums,int &count,int sum,int index,int S)    {        if (index==nums.size())        {            if(sum==S)                count+=1;            return;        }        dfs(nums,count,sum+nums[index],index+1,S);        dfs(nums,count,sum-nums[index],index+1,S);    }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 国产精品久久久久久久久久久新郎 | 国产综合久久久 | 欧美三级视频在线播放 | 四虎永久 | 久久久久久91 | 中文字幕亚洲不卡 | www中文字幕| 色片免费| 国产女人免费看a级丨片 | 精品国产欧美一区二区 | 日产精品久久久一区二区 | 午夜免费观看网站 | 亚洲精品美女久久久久久久久久 | 亚洲在线视频 | 一区二区三区日韩在线 | 成人深夜小视频 | 国产一级特黄视频 | 久久精品小视频 | 精品国产一区二区三区久久影院 | 国产伦精品一区二区三区高清 | 久久精品这里热有精品 | 日韩在线影院 | 成人一区av| 超碰在线人人 | 69av.com| 亚洲自拍一区在线观看在线观看 | 黄色影院免费观看 | 久久99精品国产99久久6男男 | www.成人.com| 11一12免费毛片 | 国产精品系列在线播放 | 国产精品美女久久久久aⅴ国产馆 | 国产精品久久久久久久久久久久久久 | 久久久成人av | 青楼18春一级毛片 | 国产成人+综合亚洲+天堂 | 欧美日韩精品一二区 | 国产精品毛片一区二区在线看 | 日韩一二三区 | 亚洲高清电影 | 一区二区三区视频 |