function combinationSum(candidates: number[], target: number): number[][] {
let result: number[][] = [];
let currentCombination: number[] = [];
function findCombinations(startIndex: number, remainingTarget: number) {
if (remainingTarget === 0) {
result.push([...currentCombination]);
return;
}
for (let i = startIndex; i < candidates.length; i++) {
if (candidates[i] > remainingTarget) {
continue;
}
currentCombination.push(candidates[i]);
findCombinations(i, remainingTarget - candidates[i]);
currentCombination.pop();
}
}
findCombinations(0, target);
return result;
}