LeetCode题解(0974):和可被K整除的子数组(Python)
发布日期:2021-06-29 20:09:37 浏览次数:2 分类:技术文章

本文共 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

转载地址:https://dataartist.blog.csdn.net/article/details/109841293 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:LeetCode题解(0981):基于时间的键值存储(Python)
下一篇:LeetCode题解(0957):N天后的牢房(Python)

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2024年04月07日 09时35分37秒