Combination Sum
Return all distinct combinations of candidate values summing to target. A candidate may be used repeatedly. Ordering within a combination and among combinations is unrestricted.
Example 1
candidates = [2,5,7]
target = 7[[2,5],[7]]Explanation
7 is formed as 2+5 or a single 7; no other combination reaches it.
Example 2
candidates = [3]
target = 8[]Explanation
Multiples of 3 cannot equal 8.
Example 3
candidates = [4]
target = 8[[4,4]]Explanation
Reuse candidate 4 twice to reach 8.
Constraints
- 1 <= number of distinct candidates <= 30
- Candidates are positive integers
- 1 <= target <= 40
Function contract
combinationSumArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[2,5,7]7