前缀和(prefix sum/cumulative sum)的应用
class Solution(object): def subarraysDivByK(self, A, K): P = [0] for x in A: P.append((P[-1] + x) % K) count = collections.Counter(P) return sum(v*(v-1)/2 for v in count.values())
Leetcode 974. Subarray Sums Divisible by K
原文:https://www.cnblogs.com/zywscq/p/10544142.html