mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-25 12:14:26 +08:00
提交尝试但未通过的题
This commit is contained in:
@ -0,0 +1,24 @@
|
||||
package leetcode
|
||||
|
||||
func combinationSum4(nums []int, target int) int {
|
||||
if len(nums) == 0 {
|
||||
return 0
|
||||
}
|
||||
c, res := []int{}, 0
|
||||
findcombinationSum4(nums, target, 0, c, &res)
|
||||
return res
|
||||
}
|
||||
|
||||
func findcombinationSum4(nums []int, target, index int, c []int, res *int) {
|
||||
if target <= 0 {
|
||||
if target == 0 {
|
||||
*res++
|
||||
}
|
||||
return
|
||||
}
|
||||
for i := 0; i < len(nums); i++ {
|
||||
c = append(c, nums[i])
|
||||
findcombinationSum4(nums, target-nums[i], i, c, res)
|
||||
c = c[:len(c)-1]
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user