
Medium
https://leetcode.com/problems/combination-sum/
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 |
Input: candidates = [2,3,6,7], target = 7, |
2019.9.1 独立做出来了
方法:
采用递归方法。
先对 candidates[] 排序,然后从大到小判断,需要注意的是由于可以同一个数字多次出现,所以递归时传入的 candidates[] 是 candidates[0:i+1]
1 |
class (object): |
类似题目:
Combination Sum II
Combinations
Combination Sum III
Factor Combinations
Combination Sum IV




近期评论