自己写出来滴,有进步,嘻嘻~
var combinationSum3 = function(k, n) {
let res=[];
backtracking(1,[],n);
return res;
function backtracking(start,temp,target){
if(target==0&&temp.length==k) res.push([...temp]);
if(target<0||temp.length>k) return;
else{
for(var i=start;i<=9;i++){
temp.push(i);
backtracking(i+1,temp,target-i);
temp.pop();
}
}
}
};