We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1fcf30c commit 33ef037Copy full SHA for 33ef037
1 file changed
python/graph/leetcode_77.py
@@ -0,0 +1,35 @@
1
+# LeetCode
2
+# 77. Combinations
3
+# https://leetcode.com/problems/combinations/
4
+
5
+def combinationLibrary(n, k):
6
7
+ number = []
8
+ result = []
9
10
+ for i in range(n):
11
+ number.append(i+1)
12
13
+ for combi in combinations(number, k):
14
+ result.append(list(combi))
15
16
+ return result
17
18
+def combination(n, k):
19
20
21
22
23
24
25
26
+ def combination(depth: int, now: [int], index: int):
27
+ if depth == k:
28
+ result.append(now)
29
+ return
30
+ else:
31
+ for i in range(index, n):
32
+ combination(depth+1, now+[number[i]], i+1)
33
34
+ combination(0, [], 0)
35
0 commit comments