添加Go语言题解

This commit is contained in:
zouxinyao
2021-07-28 02:26:32 +08:00
parent 7eb8b4a9fd
commit 575b7612f0
52 changed files with 1679 additions and 104 deletions

View File

@@ -129,3 +129,21 @@ public:
}
};
```
Go Code:
```go
func subarraysDivByK(nums []int, k int) int {
m := make(map[int]int)
cnt := 0
sum := 0
m[0] = 1
for _, num := range nums {
sum += num
key := (sum % k + k) % k
cnt += m[key]
m[key]++
}
return cnt
}
```