Skip to content

Commit

Permalink
Time: 13 ms (84.81%), Space: 9.5 MB (32.94%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Jan 7, 2025
1 parent 844c333 commit 2dada7c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions 0560-subarray-sum-equals-k/0560-subarray-sum-equals-k.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func subarraySum(nums []int, k int) int {
ans := 0
curSum := 0
m := map[int]int{0:1}

for _, v := range nums {
curSum += v
diff := curSum - k

ans += m[diff]
m[curSum]+= 1
}

return ans
}

0 comments on commit 2dada7c

Please sign in to comment.