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