mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 02:53:31 +08:00
添加0377.组合总和Ⅳ Go版本
This commit is contained in:
@ -183,7 +183,23 @@ class Solution:
|
|||||||
|
|
||||||
|
|
||||||
Go:
|
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]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user