Subarray Sums Divisible by K
Given an array A
of integers, return the number of (contiguous, non-empty) subarrays that have a sum divisible by K
.
Example 1:
Note:
1 <= A.length <= 30000
-10000 <= A[i] <= 10000
2 <= K <= 10000
分析
sum(0,i)%k = sum(0,j)%k, i+1->j之间可以被K整除。 这里注意先把当前cnt[cur] 加入res, 再increase cnt[cur] 因为每次当前Index只需要之前的数字,不是更新后数字
Last updated