Leetcode - Combination Sum
39. Combination Sum[M]
https://leetcode.com/problems/combination-sum/
Description
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
The same repeated number may be chosen from candidates unlimited number of times.
Note:
- All numbers (including
target) will be positive integers. - The solution set must not contain duplicate combinations.
Example 1:
1 | Input: candidates = [2,3,6,7], target = 7, |
Example 2:
1 | Input: candidates = [2,3,5], target = 8, |
Constraints:
1 <= candidates.length <= 301 <= candidates[i] <= 200- Each element of
candidateis unique. 1 <= target <= 500
Solution
1 |
40. Combination Sum II[M]
https://leetcode.com/problems/combination-sum-ii/
Description
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
Each number in candidates may only be used once in the combination.
Note:
- All numbers (including
target) will be positive integers. - The solution set must not contain duplicate combinations.
Example 1:
1 | Input: candidates = [10,1,2,7,6,1,5], target = 8, |
Example 2:
1 | Input: candidates = [2,5,2,1,2], target = 5, |
Solution
1 |
216. Combination Sum III[M]
https://leetcode.com/problems/combination-sum-iii/
Description
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.
Note:
- All numbers will be positive integers.
- The solution set must not contain duplicate combinations.
Example 1:
1 | Input: k = 3, n = 7 |
Example 2:
1 | Input: k = 3, n = 9 |
Solution
1 | import itertools as it |





