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

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

[leetcode]494. Target Sum

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

題目鏈接: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在线 | 欧美a视频 | 中文字幕免费在线看 | 天天干干 | 美国一级黄色毛片 | 久久国产精品久久久久久 | 嗯~啊~弄嗯~啊h高潮视频 | 国产精品爱久久久久久久 | 成年人在线免费播放视频 | 国产精品视频一区二区三区四 | 国产18视频| 久草视频在线资源 | 日本aaaa片毛片免费观蜜桃 | 久久免费视屏 | wwwxxx免费视频| 欧美成年性h版影视中文字幕 | 91美女视频在线观看 | 久久久久久久91 | 天天操天天碰 | 免费播放av | 国产在线精品区 | 午夜视频在线免费 | 国产做爰全免费的视频黑人 | 久久色播| 亚洲综合视频网站 | 成人9禁啪啪无遮挡免费 | 久久精品a一级国产免视看成人 | 日本精品一二区 | 涩涩操| 久草在线新时代视觉 | 午夜视频亚洲 | 色七七久久影院 |