We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0e8b614 commit 2042890Copy full SHA for 2042890
0077-combinations/0077-combinations.py
@@ -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