IT_World

[leetcode] 39. Combination Sum 본문

Coding test/programmers - single

[leetcode] 39. Combination Sum

engine 2022. 4. 1. 16:27
class Solution:
    def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
        result = []
        def dfs(cansum,index,path):
            if cansum < 0 :
                return
            if cansum == 0 :
                result.append(path)
                return
            for i in range(index,len(candidates)):
                dfs(cansum - candidates[i],i, path + [candidates[i]])
        dfs(target, 0, [])
        return result

'Coding test > programmers - single' 카테고리의 다른 글

[leetcode] 88. Merge Sorted Array  (0) 2022.04.03
[leetcode] 70. Climbing Stairs  (0) 2022.04.02
[leetcode]77. Combinations  (0) 2022.03.31
[leetcode]78. Subsets  (0) 2022.03.30
[leetcode] 22. Generate Parentheses  (0) 2022.03.29
Comments