From 9f3df3bc3ad6d64fed238631e310d91d46969cfa Mon Sep 17 00:00:00 2001 From: Azureki Date: Sun, 26 May 2019 21:56:29 +0800 Subject: [PATCH] python implementation --- 77. Combinations/recursive.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 77. Combinations/recursive.py diff --git a/77. Combinations/recursive.py b/77. Combinations/recursive.py new file mode 100644 index 0000000..e875df8 --- /dev/null +++ b/77. Combinations/recursive.py @@ -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