Given an array of distinct integers candidates and an integer target, return every unique combination of numbers from candidates that adds up to target. You can return the combinations in any order, and the numbers inside each one in any order too.
You can use the same number as many times as you like. Two combinations are the same if they use every number the same number of times, so [2,2,3] and [3,2,2] are one combination and should only appear once.
The tests are chosen so that every input has fewer than 150 combinations.
Examples
Example 1
Input: candidates = [2,3,6,7], target = 7
Output: [[2,2,3],[7]]
2 + 2 + 3 = 7 uses 2 twice, which is allowed. 7 on its own is also 7. No other combination adds up to 7.
Example 2
Input: candidates = [2,3,5], target = 8
Output: [[2,2,2,2],[2,3,3],[3,5]]
Example 3
Input: candidates = [2], target = 1
Output: []
Every combination of 2s adds up to an even number, and the smallest is 2. Nothing adds up to 1.
Example 4
Input: candidates = [3,5,8], target = 11
Output: [[3,3,5],[3,8]]
[5,3,3] adds up to 11 too, but it uses the same numbers as [3,3,5], so it isn't a new combination.
Constraints
1 <= candidates.length <= 302 <= candidates[i] <= 40- All the numbers in
candidatesare different. 1 <= target <= 40