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

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

[leetcode]494. Target Sum

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

題目鏈接: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);    }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美高清在线精品一区二区不卡 | 毛片免费在线观看 | 免费观看国产精品视频 | 免费男女视频 | 国产资源在线视频 | 欧美精品久久久久久久久久 | 国产在线久| 色骚综合| 久久亚洲精品久久国产一区二区 | 国产盼盼私拍福利视频99 | 黄色羞羞视频在线观看 | 久久福利在线 | 国产女同玩人妖 | 极品国产91在线网站 | 免费一级电影 | 视频在线91| 精品国产看高清国产毛片 | 亚洲一区二区中文 | 国产精品久久久乱弄 | 久久精品亚洲一区 | 毛片视频免费观看 | 视频一区二区三区在线播放 | 成人午夜毛片 | 亚洲一区成人在线 | 免费一级欧美在线观看视频 | 视频久久免费 | 九九精品在线观看视频 | 美国一级免费视频 | 中文字幕激情 | 斗罗破苍穹在线观看免费完整观看 | 13一14毛片免费看 | 免费午夜视频在线观看 | 久久久久久久爱 | 大学生一级毛片在线视频 | 日韩激情一区二区三区 | 亚洲成人中文字幕在线 | 久久久精品视频免费看 | 色七七网站 | 色中色综合网 | 亚洲成人午夜精品 | 欧美成年人视频 |