Difficult:Medium
題目
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sum to target.
Each number in candidates may only be used once in the combination.
Note: The solution set must not contain duplicate combinations.
翻譯
給定一組候選編號(candidates)和一個目標編號(target),找出候選編號總和為 target 的所有唯一組合。
候選中的每個數字在組合中只能使用一次。
注意:解決方案集不得包含重複的組合。
範例
Example 1:
1 | Input: candidates = [10,1,2,7,6,1,5], target = 8 |
Example 2:
1 | Input: candidates = [2,5,2,1,2], target = 5 |
解題思路
1.將題目分成小問題
2.利用遞迴求解
Solution
Code 1 :
1 | const combinationSum2 = (candidates, target) => { |