2022-03-27 20:38:29 +08:00
|
|
|
|
<p>给定一个<strong>无重复元素</strong>的正整数数组 <code>candidates</code> 和一个正整数 <code>target</code> ,找出 <code>candidates</code> 中所有可以使数字和为目标数 <code>target</code> 的唯一组合。</p>
|
|
|
|
|
|
|
|
|
|
<p><code>candidates</code> 中的数字可以无限制重复被选取。如果至少一个所选数字数量不同,则两种组合是不同的。 </p>
|
|
|
|
|
|
|
|
|
|
<p>对于给定的输入,保证和为 <code>target</code> 的唯一组合数少于 <code>150</code> 个。</p>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 1:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入: </strong>candidates = [2,3,6,7], target = 7
|
2022-03-27 20:38:29 +08:00
|
|
|
|
<strong>输出: </strong>[[7],[2,2,3]]
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 2:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入: </strong>candidates = [2,3,5], target = 8
|
2022-03-27 20:38:29 +08:00
|
|
|
|
<strong>输出: </strong>[[2,2,2,2],[2,3,3],[3,5]]</pre>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 3:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入: </strong>candidates = [2], target = 1
|
2022-03-27 20:38:29 +08:00
|
|
|
|
<strong>输出: </strong>[]
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 4:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入: </strong>candidates = [1], target = 1
|
2022-03-27 20:38:29 +08:00
|
|
|
|
<strong>输出: </strong>[[1]]
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p><strong>示例 5:</strong></p>
|
|
|
|
|
|
|
|
|
|
<pre>
|
2023-12-09 18:42:21 +08:00
|
|
|
|
<strong>输入: </strong>candidates = [1], target = 2
|
2022-03-27 20:38:29 +08:00
|
|
|
|
<strong>输出: </strong>[[1,1]]
|
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><strong>提示:</strong></p>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li><code>1 <= candidates.length <= 30</code></li>
|
|
|
|
|
<li><code>1 <= candidates[i] <= 200</code></li>
|
|
|
|
|
<li><code>candidate</code> 中的每个元素都是独一无二的。</li>
|
|
|
|
|
<li><code>1 <= target <= 500</code></li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<p> </p>
|
|
|
|
|
|
|
|
|
|
<p><meta charset="UTF-8" />注意:本题与主站 39 题相同: <a href="https://leetcode-cn.com/problems/combination-sum/">https://leetcode-cn.com/problems/combination-sum/</a></p>
|