Skip to content

Commit 33ef037

Browse files
committed
leetcode - 77
1 parent 1fcf30c commit 33ef037

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

python/graph/leetcode_77.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
number = []
21+
result = []
22+
23+
for i in range(n):
24+
number.append(i+1)
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

Comments
 (0)