mirror of
https://github.com/chefyuan/algorithm-base.git
synced 2026-03-12 12:51:10 +00:00
添加Go语言题解
This commit is contained in:
@@ -217,3 +217,23 @@ public:
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
Go Code:
|
||||
|
||||
```go
|
||||
func subarraySum(nums []int, k int) int {
|
||||
m := map[int]int{}
|
||||
m[0] = 1
|
||||
sum := 0
|
||||
cnt := 0
|
||||
for _, num := range nums {
|
||||
sum += num
|
||||
if v, ok := m[sum - k]; ok {
|
||||
cnt += v
|
||||
}
|
||||
m[sum]++
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user