回溯part01
/**
* @param {number} n
* @param {number} k
* @return {number[][]}
*/
var combine = function(n, k) {
let res = [];
getCombine(n, k, [], 1, res);
return res;
};
function getCombine(n, k, path, startIndex, res){
if(path.length == k){//满足条件
res.push([...path]);
}
//递归边界
if(startIndex > n) return;
for(let i = startIndex; i <= n; i++){
path.push(i);
getCombine(n, k, path, i + 1, res);
path.pop();
}
}