LeetCode Q39 組合總和

2021-09-22 13:15:57 字數 763 閱讀 3721

給定乙個無重複元素的陣列 candidates 和乙個目標數 target ,找出 candidates 中所有可以使數字和為 target 的組合。

candidates 中的數字可以無限制重複被選取。

說明:所有數字(包括 target)都是正整數。

解集不能包含重複的組合。

示例 1:

輸入: candidates = [2,3,6,7], target = 7,

所求解集為:

[[7],

[2,2,3]

]

示例 2:

輸入: candidates = [2,3,5], target = 8,

所求解集為:

[[2,2,2,2],

[2,3,3],

[3,5]

]

回溯法

class

solution

private

void

backtracking

(int

candidates,

int target, list

list,

int start)

for(

int i = start; i < candidates.length; i++)}

}}

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...