代码拉取完成,页面将自动刷新
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{
},
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。