mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-08-02 18:37:22 +08:00
Optimized solution 3、39
This commit is contained in:
@ -75,11 +75,13 @@ func findcombinationSum(nums []int, target, index int, c []int, res *[][]int) {
|
||||
return
|
||||
}
|
||||
for i := index; i < len(nums); i++ {
|
||||
if nums[i] > target { // 这里可以剪枝优化
|
||||
break
|
||||
}
|
||||
c = append(c, nums[i])
|
||||
findcombinationSum(nums, target-nums[i], i, c, res) // 注意这里迭代的时候 index 依旧不变,因为一个元素可以取多次
|
||||
c = c[:len(c)-1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
Reference in New Issue
Block a user