麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

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

[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);    }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: www.99热精品 | 91久久国产露脸精品国产护士 | 久久午夜神器 | 91av日韩 | 日本成年网| 国产午夜精品在线 | 欧美毛片| 在线视频观看一区二区 | 日本高清视频网站www | 在线91视频| 亚洲精品一区中文字幕 | 成人不卡在线观看 | 日韩欧美综合在线 | 国产精品视频 | 成人在线视频精品 | 日本在线观看中文字幕 | 久草资源在线观看 | 亚洲三区精品 | 男人的天堂毛片 | 国产一区二区久久精品 | 日本免费不卡一区二区 | 免费专区 - 91爱爱 | 欧美成人午夜影院 | 国产一区二区三区四 | 亚洲一区二区在线视频 | 毛片一级免费看 | 男女羞羞视频在线免费观看 | 成人在线观看免费爱爱 | 一级电影在线免费观看 | av电影在线网站 | 天天干干 | 19禁国产精品福利视频 | av老司机久久 | 一级毛片在线免费观看视频 | 久久久一区二区精品 | 天天干天天透 | 精品国产乱码久久久久久丨区2区 | 成人午夜一区二区 | 国产精品99久久久久久久 | 国产精品99久久久久久久 | 国产一级毛片不卡 |