Given two integers n and k, return all possible combinations of k numbers out of the range [1, n].
You may return the answer in any order.
/**
* @param {number} n
* @param {number} k
* @return {number[][]}
*/
var combine = function(n, k) {
let ans = comb(n, k);
return ans;
};
let comb = function(n, k, res = [], curr = [], index = 1) {
if(curr.length === k) {
res.push(curr);
return;
}
else {
while(index <= n) {
comb(n, k, res, [...curr, index], ++index);
}
return res
}
}