Skip to content

Commit 1ecd634

Browse files
committed
Time: 55 ms (82.04%), Space: 129.4 MB (24.17%) - LeetHub
source:01b8a4f834bf58178c0f6c89a7d6eaaf4858352a
1 parent 3dadbf9 commit 1ecd634

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @param {number} n
3+
* @param {number} k
4+
* @return {number[][]}
5+
*/
6+
var combine = function(n, k) {
7+
const result = [];
8+
9+
function dfs(start, path) {
10+
if (path.length === k) {
11+
result.push([...path]);
12+
return;
13+
}
14+
15+
for (let i = start; i <= n; i++) {
16+
path.push(i);
17+
dfs(i + 1, path);
18+
path.pop();
19+
}
20+
}
21+
22+
dfs(1, []);
23+
24+
return result;
25+
}

0 commit comments

Comments
 (0)