Skip to content

Commit 2042890

Browse files
committed
Time: 142 ms (36.19%), Space: 59.6 MB (87.09%) - LeetHub
1 parent 0e8b614 commit 2042890

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# time complexity: O(n!)
2+
# space complexity: O(n)
3+
class Solution:
4+
def combine(self, n: int, k: int) -> List[List[int]]:
5+
result = []
6+
7+
def backtrack(start, comb):
8+
if len(comb) == k:
9+
result.append(list(comb))
10+
return
11+
12+
for i in range(start, n + 1):
13+
comb.append(i)
14+
backtrack(i + 1, comb)
15+
comb.pop()
16+
17+
18+
backtrack(1, [])
19+
return result

0 commit comments

Comments
 (0)