添加0377.组合总和Ⅳ Go版本
This commit is contained in:
parent
16f5dd51da
commit
5243b5eac0
|
|
@ -183,7 +183,23 @@ class Solution:
|
|||
|
||||
|
||||
Go:
|
||||
|
||||
```go
|
||||
func combinationSum4(nums []int, target int) int {
|
||||
//定义dp数组
|
||||
dp := make([]int, target+1)
|
||||
// 初始化
|
||||
dp[0] = 1
|
||||
// 遍历顺序, 先遍历背包,再循环遍历物品
|
||||
for j:=0;j<=target;j++ {
|
||||
for i:=0 ;i < len(nums);i++ {
|
||||
if j >= nums[i] {
|
||||
dp[j] += dp[j-nums[i]]
|
||||
}
|
||||
}
|
||||
}
|
||||
return dp[target]
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue