1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-13 03:11:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

add leetcode problem-cn part5

This commit is contained in:
2022-03-27 20:52:13 +08:00
parent 053330914a
commit c11d601602
326 changed files with 26353 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>target</code></p>
<p>向数组中的每个整数前添加 <code>'+'</code><code>'-'</code> ,然后串联起所有整数,可以构造一个 <strong>表达式</strong> </p>
<ul>
<li>例如,<code>nums = [2, 1]</code> ,可以在 <code>2</code> 之前添加 <code>'+'</code> ,在 <code>1</code> 之前添加 <code>'-'</code> ,然后串联起来得到表达式 <code>"+2-1"</code></li>
</ul>
<p>返回可以通过上述方法构造的、运算结果等于 <code>target</code> 的不同 <strong>表达式</strong> 的数目。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,1,1,1,1], target = 3
<strong>输出:</strong>5
<strong>解释:</strong>一共有 5 种方法让最终目标和为 3 。
-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 = 3
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1], target = 1
<strong>输出:</strong>1
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 20</code></li>
<li><code>0 <= nums[i] <= 1000</code></li>
<li><code>0 <= sum(nums[i]) <= 1000</code></li>
<li><code>-1000 <= target <= 1000</code></li>
</ul>