|
1 | 1 | # Combination Sum
|
2 | 2 |
|
| 3 | +Tags: Array, Backtracking, Medium |
| 4 | + |
3 | 5 | ## Question
|
4 | 6 |
|
5 |
| -- leetcode: [Combination Sum | LeetCode OJ](https://leetcode.com/problems/combination-sum/) |
6 |
| -- lintcode: [(135) Combination Sum](http://www.lintcode.com/en/problem/combination-sum/) |
| 7 | +- leetcode: [Combination Sum](https://leetcode.com/problems/combination-sum/) |
| 8 | +- lintcode: [Combination Sum](https://www.lintcode.com/problem/combination-sum/) |
| 9 | + |
| 10 | +### Problem Statement |
| 11 | + |
| 12 | +Given a **set** of candidate numbers (`candidates`) **(without duplicates)** |
| 13 | +and a target number (`target`), find all unique combinations in `candidates` |
| 14 | +where the candidate numbers sums to `target`. |
| 15 | + |
| 16 | +The **same** repeated number may be chosen from `candidates` unlimited number |
| 17 | +of times. |
| 18 | + |
| 19 | +**Note:** |
| 20 | + |
| 21 | + * All numbers (including `target`) will be positive integers. |
| 22 | + * The solution set must not contain duplicate combinations. |
| 23 | + |
| 24 | +**Example 1:** |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + **Input:** candidates = [2,3,6,7], target = 7, |
| 29 | + **A solution set is:** |
| 30 | + [ |
| 31 | + [7], |
| 32 | + [2,2,3] |
| 33 | + ] |
| 34 | + |
| 35 | + |
| 36 | +**Example 2:** |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + **Input:** candidates = [2,3,5], target = 8, |
| 41 | + **A solution set is:** |
| 42 | + [ |
| 43 | + [2,2,2,2], |
| 44 | + [2,3,3], |
| 45 | + [3,5] |
| 46 | + ] |
7 | 47 |
|
8 |
| -``` |
9 |
| -Given a set of candidate numbers (C) and a target number (T), |
10 |
| -find all unique combinations in C where the candidate numbers sums to T. |
11 |
| -The same repeated number may be chosen from C unlimited number of times. |
12 |
| -
|
13 |
| -For example, given candidate set 2,3,6,7 and target 7, |
14 |
| -A solution set is: |
15 |
| -[7] |
16 |
| -[2, 2, 3] |
17 |
| -
|
18 |
| -Have you met this question in a real interview? Yes |
19 |
| -Example |
20 |
| -given candidate set 2,3,6,7 and target 7, |
21 |
| -A solution set is: |
22 |
| -[7] |
23 |
| -[2, 2, 3] |
24 |
| -
|
25 |
| -Note |
26 |
| -- All numbers (including target) will be positive integers. |
27 |
| -- Elements in a combination (a1, a2, … , ak) must be in non-descending order. |
28 |
| -(ie, a1 ≤ a2 ≤ … ≤ ak). |
29 |
| -- The solution set must not contain duplicate combinations. |
30 |
| -``` |
31 | 48 |
|
32 | 49 | ## 题解
|
33 | 50 |
|
|
0 commit comments