1 Star 0 Fork 0

ljfirst/algo-go-sdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
CombinationNum_Dynamic.go 1.17 KB
一键复制 编辑 原始数据 按行查看 历史
ljfirst 提交于 2023-07-04 23:35 +08:00 . feat: PriorityQueue
package dynamic
import C "gitee.com/ljfirst/algo-go-sdk/common/constant"
/**
* @author ljfirst
* @version V1.0
* @date 2023/7/27 22:33
* @author-Email ljfirst@mail.ustc.edu.cn
* @blogURL https://blog.csdn.net/ljfirst
* @description
**/
type CombinationNum_Dynamic struct {
}
func (m *CombinationNum_Dynamic) Method(array []int, target int) bool {
if len(array) == 0 {
return false
}
if target < 0 { // 可能存在负数情况,所以需要进行判断
target = -target
}
result := make([]bool, target+1, target+1) // 为什么是target+1?因为是从0开始的,直到target
result[0] = true
for i := 1; i <= target; i++ {
for _, v := range array {
if i-v > 0 {
result[i] = result[i-v]
}
if result[i] {
break
}
}
}
return result[target]
}
func (m *CombinationNum_Dynamic) GetAttribute() *C.Attribute {
return &C.Attribute{
Tags: []string{},
Desc: &C.Desc{
Name: "CombinationNum_Dynamic",
NameCn: "",
Description: "判断数组中是否存在这样几个数,使得和等于 target(数组元素 不可以 无限重复的选择)",
ParamsDesc: map[string]string{
},
Example: map[int]string{
},
},
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/ljfirst/algo-go-sdk.git
git@gitee.com:ljfirst/algo-go-sdk.git
ljfirst
algo-go-sdk
algo-go-sdk
v1.0.3

搜索帮助