프로그래밍/LeetCode

[LeetCode][Python3] 216. Combination Sum III

snoopybox 2019. 8. 23. 21:25

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
저작자표시 (새창열림)