216. Combination Sum III
Analysis:
- Same as 39 & 49.
- Keep the numbers in returned set in accending order to avoid duplicates.
- trim the tree by judging if a number is greater than target
- take care of the boundary: n==0, k ==0
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 |
Soulution:
1 | class Solution: |