Files
leetcode/top-100-liked/10_1_test.go
T
2026-05-31 05:06:57 +10:00

27 lines
440 B
Go

package top100liked
import "testing"
// https://leetcode.cn/problems/continuous-subarray-sum/
func checkSubarraySum(nums []int, k int) bool {
idx := make(map[int]int)
cur := 0
idx[0] = -1
for i, v := range nums {
cur += v
if j, ok := idx[cur%k]; ok {
if i-j >= 2 {
return true
}
} else {
idx[cur%k] = i
}
}
return false
}
func TestS10_1(t *testing.T) {
println(checkSubarraySum([]int{23, 2, 6, 4, 7}, 13))
}