mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-07 01:44:56 +08:00
Add solution 0097、0523、0525、1465、1744
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
package leetcode
|
||||
|
||||
func checkSubarraySum(nums []int, k int) bool {
|
||||
m := make(map[int]int)
|
||||
m[0] = -1
|
||||
sum := 0
|
||||
for i, n := range nums {
|
||||
sum += n
|
||||
if r, ok := m[sum%k]; ok {
|
||||
if i-2 >= r {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
m[sum%k] = i
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user