https://leetcode-cn.com/problems/combination-sum/
/**
* @param {number[]} candidates
* @param {number} target
* @return {number[][]}
*/
var combinationSum = function(candidates, target) {
let res = []
let len = candidates.length
const defs = (path ,start, total) => {
for (let i = start; i < len; i++) {
let num = candidates[i]
if (total < target) {
path.push(num)
defs(path, i, total + num)
path.pop()
}
if (total === target) {
res.push(path.slice())
break
}
if (total > target) {
continue
}
}
}
defs([] ,0,0)
return res
};