1 Star 0 Fork 0

catyMap/AlgorithmNote

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
checkSubarraySum.go 347 Bytes
一键复制 编辑 原始数据 按行查看 历史
catyMap 提交于 2021-06-03 08:46 +08:00 . 添加一些前缀和题目
package main
func checkSubarraySum(nums []int, k int) bool {
mp := make(map[int]int)
mp[0] = -1
rem := 0
for i, v := range nums {
rem = (rem + v) % k
if idx, ok := mp[rem] ; ok && i - idx >= 2 {
return true
}else if _, ok := mp[rem] ; !ok {
mp[rem] = i
}
}
return false
}
func main() {
checkSubarraySum([]int{0,1}, 124)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/dogemap/algorithm-note.git
git@gitee.com:dogemap/algorithm-note.git
dogemap
algorithm-note
AlgorithmNote
dc486f96f6c1

搜索帮助