/**
* @param {number[]} candidates
* @param {number} target
* @return {number[][]}
*/
var combinationSum = function(candidates, target) {
let result = [];
let tempArray = [];
backTrackRecord(candidates, target, result, tempArray, 0);
return result;
};
const backTrackRecord = (candidates, target, result, tempArray, currIndex) => {
if (target === 0) {
result.push([...tempArray]);
return false;
}
if (target < 0) {
return false;
}
for (let i = currIndex; i < candidates.length; i++) {
tempArray.push(candidates[i]);
backTrackRecord(candidates, target - candidates[i], result, tempArray, i);
tempArray.pop(candidates[i]);
}
};
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)