-
[LeetCode] Combination Sum알고리즘 2020. 5. 4. 16:39
문제
Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.
The same repeated number may be chosen from candidates unlimited number of times.
Note:
- All numbers (including target) will be positive integers.
- The solution set must not contain duplicate combinations.
Example 1:
Input: candidates = [2,3,6,7], target = 7, A solution set is: [ [7], [2,2,3] ]
Example 2:
Input: candidates = [2,3,5], target = 8, A solution set is: [ [2,2,2,2], [2,3,3], [3,5] ]
Approach
DFS를 활용한 Backtracking으로 풀었다.
Code
https://github.com/chi3236/algorithm/blob/master/LeetCode_CombinationSum.cpp
'알고리즘' 카테고리의 다른 글
[LeetCode] Jump Game2 (0) 2020.08.30 [LeetCode] Linked List Cycle (0) 2020.08.23 [LeetCode] Word Break II (0) 2019.12.19 [LeetCode] Word Break (0) 2019.12.19 [LeetCode] Copy List with Random Pointer (0) 2019.12.18