https://leetcode.com/problems/combination-sum/description/
LeetCode - The World's Leading Online Programming Learning Platform
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
너무 쉬운 간단한 backtracking 문제
class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
answer = []
def dfs(comb, ind, remaining):
if remaining == 0:
answer.append(comb[:])
return
for i in range(ind, len(candidates)):
if remaining >= candidates[i]:
dfs(comb + [candidates[i]], i, remaining - candidates[i])
dfs([], 0, target)
return answer'코딩 테스트 및 알고리즘 > Grind 75 (Blind 75 Leetcode Questions)' 카테고리의 다른 글
| Array : Merge Intervals (0) | 2024.02.17 |
|---|---|
| Array : Product of Array Except Self (0) | 2024.02.17 |
| Array : Non-overlapping Intervals (0) | 2024.02.15 |
| LinkedList : Reorder List (0) | 2024.01.23 |
| LinkedList : Sort List (0) | 2024.01.21 |