-
39. Combination SumProgramming/leetcode 2021. 3. 3. 13:43728x90
재귀 호출 돌리면서 target 값이 되면 result에 저장하면 되는 문제
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: results = [] def dfs(index, cur, path): if cur < 0: return if cur == 0: results.append(path) return for i in range(index, len(candidates)): dfs(i, cur-candidates[i], path + [candidates[i]]) dfs(0, target, []) return results
'Programming > leetcode' 카테고리의 다른 글
743. Network Delay Time (0) 2021.03.10 78. Subsets (0) 2021.03.03 17. Letter Combinations of a Phone Number (0) 2021.02.24 200. Number of Islands (0) 2021.02.24 DFS, BFS (0) 2021.02.23