給定乙個無重複元素的陣列 candidates 和乙個目標數 target ,找出 candidates 中所有可以使數字和為 target 的組合。
candidates 中的數字可以無限制重複被選取。
輸入: candidates = [2,3,6,7], target = 7,
所求解集為:
[ [7],
[2,2,3]
]
輸入: candidates = [2,3,5], target = 8,
所求解集為:
[ [2,2,2,2],
[2,3,3],
[3,5]
]
class
solution
void
dfs(
const vector<
int>
& data,
int index,
int target, vector<
int>
& temp )
for(
int i = index; i < data.
size()
&& target - data[i]
>=0;
++i )
return;}
};
39 組合總和
給定乙個無重複元素的陣列 candidates 和乙個目標數 target 找出 candidates 中所有可以使數字和為 target 的組合。candidates 中的數字可以無限制重複被選取。說明 示例 1 輸入 candidates 2,3,6,7 target 7,所求解集為 7 2,2...
39 組合總和
給定乙個無重複元素的陣列candidates和乙個目標數target,找出candidates中所有可以使數字和為target的組合。candidates中的數字可以無限制重複被選取。說明 示例 1 輸入 candidates 2,3,6,7 target 7,所求解集為 7 2,2,3 示例 2 ...
39 組合總和
給定乙個無重複元素的陣列candidates和乙個目標數target,找出candidates中所有可以使數字和為target的組合。candidates中的數字可以無限制重複被選取。說明 輸入 candidates 2,3,6,7 target 7,所求解集為 7 2,2,3 輸入 candida...