本文共 419 字,大约阅读时间需要 1 分钟。
题目:(中等)
标签:哈希表、数组
解法 | 时间复杂度 | 空间复杂度 | 执行用时 |
---|---|---|---|
Ans 1 (Python) | O ( N ) O(N) O(N) | O ( K ) O(K) O(K) | 356ms (83.96%) |
Ans 2 (Python) | |||
Ans 3 (Python) |
解法一:
class Solution: def subarraysDivByK(self, A: List[int], K: int) -> int: count = collections.Counter({ 0: 1}) ans = 0 last = 0 for n in A: last = (last + n) % K ans += count[last] count[last] += 1 return ans
转载地址:http://zczcf.baihongyu.com/