1 Star 0 Fork 0

catyMap/AlgorithmNote

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
TwoSum.go 617 Bytes
一键复制 编辑 原始数据 按行查看 历史
catyMap 提交于 2022-01-22 21:52 +08:00 . 更新题库
package main
type TwoSum struct {
book map[int]int
}
/** Initialize your data structure here. */
func Constructor() TwoSum {
return TwoSum{
make(map[int]int),
}
}
/** Add the number to an internal data structure.. */
func (this *TwoSum) Add(number int) {
this.book[number]++
}
/** Find if there exists any pair of numbers which sum is equal to the value. */
func (this *TwoSum) Find(value int) bool {
for key := range this.book {
if times, ok := this.book[value-key]; ok {
if value-key == key && times >= 2 {
return true
} else if value-key != key {
return true
}
}
}
return false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助