Skip to content

Commit

Permalink
python implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Azureki committed May 26, 2019
1 parent 1ac3b7e commit 9f3df3b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 77. Combinations/recursive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def combine(self, n: int, k: int) -> List[List[int]]:
if not (0 <= k <= n):
return []
if k == 0:
return [[]]
res = self.combine(n - 1, k - 1)
for x in res:
x.append(n)
for x in self.combine(n - 1, k):
res.append(x)
return res

0 comments on commit 9f3df3b

Please sign in to comment.