Package g0001_0100.s0039_combination_sum
Class Solution
java.lang.Object
g0001_0100.s0039_combination_sum.Solution
39 - Combination Sum.<p>Medium</p>
<p>Given an array of <strong>distinct</strong> integers <code>candidates</code> and a target integer <code>target</code>, return <em>a list of all <strong>unique combinations</strong> of</em> <code>candidates</code> <em>where the chosen numbers sum to</em> <code>target</code><em>.</em> You may return the combinations in <strong>any order</strong>.</p>
<p>The <strong>same</strong> number may be chosen from <code>candidates</code> an <strong>unlimited number of times</strong>. Two combinations are unique if the frequency of at least one of the chosen numbers is different.</p>
<p>It is <strong>guaranteed</strong> that the number of unique combinations that sum up to <code>target</code> is less than <code>150</code> combinations for the given input.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> candidates = [2,3,6,7], target = 7</p>
<p><strong>Output:</strong> [[2,2,3],[7]]</p>
<p><strong>Explanation:</strong></p>
<pre><code> 2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.
7 is a candidate, and 7 = 7.
These are the only two combinations.
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> candidates = [2,3,5], target = 8</p>
<p><strong>Output:</strong> [[2,2,2,2],[2,3,3],[3,5]]</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> candidates = [2], target = 1</p>
<p><strong>Output:</strong> []</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> candidates = [1], target = 1</p>
<p><strong>Output:</strong> <a href="1">1</a></p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> candidates = [1], target = 2</p>
<p><strong>Output:</strong> <a href="1,1">1,1</a></p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= candidates.length <= 30</code></li>
<li><code>1 <= candidates[i] <= 200</code></li>
<li>All elements of <code>candidates</code> are <strong>distinct</strong>.</li>
<li><code>1 <= target <= 500</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
combinationSum
-