LeetCode p39 Combination Sum 题解
1.题目:
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
The same repeated number may be chosen from C unlimited number of times.
Note:
All numbers (including target) will be positive integers.
The solution set must not contain duplicate combinations.
For example, given candidate set [2, 3, 6, 7] and target 7,
A solution set is:
[
[7],
[2, 2, 3]
]
题意:
给一个数组,和一个数k,从你这个数组中选取一些数(可以重复),是和为k。
输出所有的组合方式。
2.解题思路:
见代码,递归。
先把数组排序。
3.代码
1 |
|