问题描述:
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.(就是要求你从1~9之间找到K个数,使得它们的和正好等于n,应该是很好理解的一道题吧)
示例:
Example 1:
Input: k = 3, n = 7
Output:
[[1,2,4]]
Example 2:
Input: k = 3, n = 9
Output:
[[1,2,6], [1,3,5], [2,3,4]]
问题来源:Combination Sum III (详细地址:https://leetcode.com/problems/combination-sum-iii/#/description)
思路:其实与Combination Sum 和Combination Sum II 两道题的解题思路没啥不一样的地方,要说不一样的地方就是这不用排序了,而且保证每次处理的数字也不一样了。所以说啊,这道题其实是变得简单了。另外,本人把Combination Sum解题过程 和 Combination Sum II解题过程 摆到一块来,方便找出相似处和不同的地方。
代码: