Problem :

https://leetcode.com/problems/combination-sum-iii/


My Solution :

class Solution:
def combinationSum3(self, k, n):
def dfs(k, n, path, num):
if k == 0 or n < num or 9 < num:
if k == n == 0:
ans.append(path[:])
return
dfs(k-1, n-num, path+[num], num+1)
dfs(k, n, path, num+1)

ans = []
dfs(k, n, [], 1)
return ans