Given an array of distinct integers nums
and a target integer target
, return all unique combinations of numbers from nums
that sum to target
.
Rules:
nums
are distinctConstraints:
Examples:
// Example 1: console.log(combinationSum([2,5,6,9], 9)); // Output: [[2,2,5], [9]] // Explanation: // 2 + 2 + 5 = 9 // 9 = 9 // Example 2: console.log(combinationSum([3,4,5], 16)); // Output: [[3,3,3,3,4], [3,3,5,5], [4,4,4,4], [3,4,4,5]] // Example 3: console.log(combinationSum([3], 5)); // Output: [] // Explanation: No combinations sum to 5