216. Combination Sum III
problem 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:
Example 2:
algorithm thought
组合问题,直接用回溯法解决,中间加入剪枝,如果sum已经大于n了,就可以不用继续往下求解了
code
algorithm analysis
遍历求解3个数的组合,时间复杂度 O(C(9,k))-> O(9^k), 空间复杂度: k
Last updated