1 Star 0 Fork 0

ljfirst/algo-go-sdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TwoSum.go 862 Bytes
一键复制 编辑 原始数据 按行查看 历史
ljfirst 提交于 2023-07-04 23:35 +08:00 . feat: PriorityQueue
package two_point
import (
C "gitee.com/ljfirst/algo-go-sdk/common/constant"
"sort"
)
/**
* @author ljfirst
* @version V1.0
* @date 2023/7/27 15:49
* @author-Email ljfirst@mail.ustc.edu.cn
* @blogURL https://blog.csdn.net/ljfirst
* @description
**/
type TwoSum struct {
}
func (m *TwoSum) Method(array []int, target int) []int {
if len(array) == 0 {
return nil
}
sort.Ints(array)
l, r := 0, len(array)-1
for l < r {
if array[l]+array[r] == target {
return []int{array[l], array[r]}
} else if array[l]+array[r] < target {
l++
} else {
r--
}
}
return nil
}
func (m *TwoSum) GetAttribute() *C.Attribute {
return &C.Attribute{
Tags: []string{},
Desc: &C.Desc{
Name: "TwoSum",
NameCn: "两数之和",
Description: "",
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

搜索帮助