Class Solution
java.lang.Object
g0201_0300.s0216_combination_sum_iii.Solution
216 - Combination Sum III.<p>Medium</p>
<p>Find all valid combinations of <code>k</code> numbers that sum up to <code>n</code> such that the following conditions are true:</p>
<ul>
<li>Only numbers <code>1</code> through <code>9</code> are used.</li>
<li>Each number is used <strong>at most once</strong>.</li>
</ul>
<p>Return <em>a list of all possible valid combinations</em>. The list must not contain the same combination twice, and the combinations may be returned in any order.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> k = 3, n = 7</p>
<p><strong>Output:</strong> <a href="1,2,4">1,2,4</a></p>
<p><strong>Explanation:</strong></p>
<pre><code> 1 + 2 + 4 = 7
There are no other valid combinations.
</code></pre>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> k = 3, n = 9</p>
<p><strong>Output:</strong> [[1,2,6],[1,3,5],[2,3,4]]</p>
<p><strong>Explanation:</strong></p>
<pre><code> 1 + 2 + 6 = 9
1 + 3 + 5 = 9
2 + 3 + 4 = 9
There are no other valid combinations.
</code></pre>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> k = 4, n = 1</p>
<p><strong>Output:</strong> []</p>
<p><strong>Explanation:</strong></p>
<pre><code> There are no valid combinations.
Using 4 different numbers in the range [1,9], the smallest sum we can get is 1+2+3+4 = 10 and since 10 > 1, there are no valid combination.
</code></pre>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> k = 3, n = 2</p>
<p><strong>Output:</strong> []</p>
<p><strong>Explanation:</strong> There are no valid combinations.</p>
<p><strong>Example 5:</strong></p>
<p><strong>Input:</strong> k = 9, n = 45</p>
<p><strong>Output:</strong> <a href="1,2,3,4,5,6,7,8,9">1,2,3,4,5,6,7,8,9</a></p>
<p><strong>Explanation:</strong></p>
<pre><code> 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45
There are no other valid combinations.
</code></pre>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= k <= 9</code></li>
<li><code>1 <= n <= 60</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
combinationSum3
-